Search code examples
visual-studio-2013natvis

Expand members of templated type on first expansion level of natvis visualiser


The default visualiser for shared_ptr in VS2013 has this (many, many things trimmed out!):

<Type Name="CA::shared_ptr&lt;*&gt;">
  <Expand>
    <Item Condition="_Ptr != 0" Name="[ptr]">_Ptr</Item>
  </Expand>
</Type>

This means that in the debugger you have to expand the shared_ptr then expand the [ptr] 'member' to see the pointed-to object's members. The hierarchy for a pointer to int would look like (ignoring raw views, allocators and deleters):

myIntPtr
  [ptr]
    42

I'd like to write a replacement which places all the pointed-to object's members one level up, to sit at the level in the hierarchy where [ptr] currently sits. This would instead look like:

myIntPtr
  42

Is there some syntax that will allow that? I should note, I'm looking for general syntax to support displaying all of a template parameter's members, rather than something that will only work with shared_ptr - shared_ptr is just a handy example.


Solution

  • I think this is what the "ExpandedItem" tag is good for. They even give an example that is similar to yours. See here: http://msdn.microsoft.com/en-us/library/jj620914.aspx#BKMK_ExpandedItem_expansion