Visual c++ 用于c++;工会/结构

Visual c++ 用于c++;工会/结构,visual-c++,visual-studio-debugging,natvis,Visual C++,Visual Studio Debugging,Natvis,我正在尝试使用msvc natvis visualizer实现一个个人可视化工具。问题是我不知道如何处理工会问题。 一个结构(value)包含两个结构的并集(string1和string2)的简单示例: 我可以使用natvis中的以下代码为string1和string2创建两种类型: <Type Name="string1"> /// (A) preview <DisplayString>{{ string 1 }}</DisplayString>

我正在尝试使用msvc natvis visualizer实现一个个人可视化工具。问题是我不知道如何处理工会问题。 一个结构(
value
)包含两个结构的并集(
string1
string2
)的简单示例:

我可以使用natvis中的以下代码为string1和string2创建两种类型:

<Type Name="string1"> /// (A) preview
    <DisplayString>{{ string 1 }}</DisplayString>
    <Expand>
      <Item Name="text">data</Item>
    </Expand>
  </Type>
<Type Name="string2">  /// (B) preview
    <DisplayString>{{ string 2 }}</DisplayString>
    <Expand>
      <Item Name="text">data</Item>
    </Expand>
  </Type>
//(A)预览
{{string 1}}
数据
///(B)预览
{{string 2}}
数据
但是,当我有一个“value”变量(union)时,如何自动预览这些类型呢。 我坚持这一点:(假设变量类型等于1表示string1,2表示string2)。我已经做了:

 <Type Name="value">
    <DisplayString>{{Value}}</DisplayString>
    <Expand>
            <Synthetic Name="String 1 Name" Condition="type==1"> // assume type of string1 = 1
                  /// here i want to call preview I have created for string1 in (A)
            </Synthetic>

             <Synthetic Name="String 2 Name" Condition="type==2"> // assume type of string2 = 2
                 /// here i want to call preview I have created for string2 in (B)
             </Synthetic>
   </Expand>
</Type>

{{Value}}
//假设string1的类型为1
///这里我想调用我在(A)中为string1创建的预览
//假设string2的类型为2
///这里我想调用我在(B)中为string2创建的预览
因此,我希望根据类型值,调试将显示正确的可视化工具。 你能给我解释一下如何与纳维斯打交道吗?还是有什么例子?(官方MSVC文档不考虑工会…)
显然,这个例子毫无意义,但它只是为了理解,因为我有一个更复杂的联合体。

以下应该是可行的:

<Type Name="value">
  <DisplayString Condition="type == 1">{t.sval}</DisplayString>
  <DisplayString Condition="type == 2">{t.sval2}</DisplayString>
  <Expand>
    <ExpandedItem Condition="type == 1">t.sval</ExpandedItem>
    <ExpandedItem Condition="type == 2">t.sval2</ExpandedItem>
  </Expand>
</Type>

{t.sval}
{t.sval2}
t、 斯瓦尔
t、 sval2
ExpandedItem删除联合的视图并使用string1 resp。改为string2扩展,具体取决于类型的值

我还没有尝试使用我在这里发布的XML,所以可能会有一些语法错误,但是您应该能够通过一些小的调整(如果有的话)让它工作

<Type Name="value">
  <DisplayString Condition="type == 1">{t.sval}</DisplayString>
  <DisplayString Condition="type == 2">{t.sval2}</DisplayString>
  <Expand>
    <ExpandedItem Condition="type == 1">t.sval</ExpandedItem>
    <ExpandedItem Condition="type == 2">t.sval2</ExpandedItem>
  </Expand>
</Type>