title: Natvis visualizer for c++ union/structure
body: <p>I'm trying to implement a personal visualizer using msvc natvis visualizer. The problem is that I don't know how to do it regarding union.
  A simple example with a structure ( <code>value</code>) containing a union of two structure (<code>string1</code> and <code>string2</code> ):</p>
  
  <pre><code>typedef struct value                      
  {   int type;                                              /* variable type */
      union                                                         
      {
           string1    sval;                                 
           string2    sval2;                                  
      } t;
  } 
  
  typedef struct string1
  {  
      int    size;
      char  *data;
  } aString1;
  
  typedef struct string2
  {   
      int    size;
      char  *data;
  } aString2;
  </code></pre>
  
  <p>I can create two type for string1 and string2 with the following code in natvis :</p>
  
  <pre><code>&lt;Type Name="string1"&gt; /// (A) preview
      &lt;DisplayString&gt;{{ string 1 }}&lt;/DisplayString&gt;
      &lt;Expand&gt;
        &lt;Item Name="text"&gt;data&lt;/Item&gt;
      &lt;/Expand&gt;
    &lt;/Type&gt;
  &lt;Type Name="string2"&gt;  /// (B) preview
      &lt;DisplayString&gt;{{ string 2 }}&lt;/DisplayString&gt;
      &lt;Expand&gt;
        &lt;Item Name="text"&gt;data&lt;/Item&gt;
      &lt;/Expand&gt;
    &lt;/Type&gt;
  </code></pre>
  
  <p>But how can I automatically preview these type when I have a "value" variable (the union).
  I’m stuck to this point :  (assuming the variable type equals 1 to indicate string1, and  2 for string2 ). I have done :</p>
  
  <pre><code> &lt;Type Name="value"&gt;
      &lt;DisplayString&gt;{{Value}}&lt;/DisplayString&gt;
      &lt;Expand&gt;
              &lt;Synthetic Name="String 1 Name" Condition="type==1"&gt; // assume type of string1 = 1
                    /// here i want to call preview I have created for string1 in (A)
              &lt;/Synthetic&gt;
  
               &lt;Synthetic Name="String 2 Name" Condition="type==2"&gt; // assume type of string2 = 2
                   /// here i want to call preview I have created for string2 in (B)
               &lt;/Synthetic&gt;
     &lt;/Expand&gt;
  &lt;/Type&gt;
  </code></pre>
  
  <p>So I would like that depending of the type value, the debug will show the correct visualizer.
  Can you explain me how to deal with union with natvis ? or is there somewhere an example ? (the official msvc documentation do not consider unions..)
  Obvioulsy this example makes no sense but it is just to understand because I have a far more complex union.</p>