5

I created form with grid to visualize any collection (ICollection, ICollection<T>) object.

After that I created debugger visualizer class (inherits from Microsoft.VisualStudio.DebuggerVisualizers.DialogDebuggerVisualizer).

The visualizer is installed propertly (I tried it on System.Collections.ArrayList class).

But I have problem with generalize the visualizer to any ICollection/ICollection<T> type.

I specified attribute:

[assembly: DebuggerVisualizer( typeof( DebugerSide ), typeof( VisualizerObjectSource ), Target = typeof( System.Collections.Generic.ICollection<> ), Description = "Collection visualizer" )]
[assembly: DebuggerVisualizer( typeof( DebugerSide ), typeof( VisualizerObjectSource ), Target = typeof( System.Collections.ICollection ), Description = "Collection visualizer" )]

but the visualizer is not offered by VS in debug.

If I specify exactl class name, the visualizer is available in VS. Is there way, how to perform my intention or there is no way, how to achieve it?

Thanks!

TcKs
  • 25,849
  • 11
  • 66
  • 104

2 Answers2

9

I think you've stumbled into the same limitation of the Visualizers architecture as outlined in this question.

The workaround is to create a Visualizer for System.WeakReference, and then to type in the Watch window "new WeakReference(myCollectionVariable)", and then you will be able to open your debug visualizer on the weakreference. Inside your debug visualizer you can use reflection to find out what exactly the type of your variable is, and do whatever you want with it.

See also this.

Community
  • 1
  • 1
Omer Raviv
  • 11,409
  • 5
  • 43
  • 82
  • Thank you! The workaround looks littlebit crazy. But it will be propably only way, how to achieve my purpose. – TcKs Jul 11 '11 at 16:25
  • The problem is that you cannot create a visualizer for a generic class, or that you cannot register same visualizer for 2 "different" types? – lysergic-acid Jul 13 '11 at 18:32
  • 3
    Debugger visualizers won't work on interface types, only on classes (except System.Array and System.Object). You have to specify a specific class. You can create a visualizer for a generic class, but support is limited to open generic types - as documented at: http://msdn.microsoft.com/en-us/library/e2zc529c.aspx – Omer Raviv Jul 13 '11 at 19:15
  • @Omer Raviv: Your tip looks like the only posible way. Thanks for answer! – TcKs Jul 14 '11 at 08:43
0

This will work fine i guess.

[assembly: DebuggerVisualizer( typeof( DebugerSide ), typeof( VisualizerObjectSource ), typeof(Collection), Description = "Collection visualizer" )]
Murugan
  • 1,441
  • 1
  • 12
  • 22