Dr. Rajesh Rolen
Dr. Rajesh Rolen

Reputation: 14285

Visual studio custom visualizer target type for user defined classes and collections

I have written one custom visualizer for visual studio, which works on class (user defined) and collection (generics).

But its now showing in application. i have put the dlls on proper place and thats not a issue...

the issue is its Type defining.

I have put below attribute on visualizer class.

[assembly: System.Diagnostics.DebuggerVisualizer(
typeof(ObjectToI.WriteICodeFromObject),
typeof(VisualizerObjectSource),
Target = typeof(System.Object),**here i am not sure what to put as my visualizer will work for both user defined classes and generics collections.**
Description = "Object To I Code Visualizer")]

please suggest what should i put in target type as my visualizer will work for user defined classes and lists/IEnumerable.

I have tried System.Object but that is not working

I have tried System.Collections.Generic.IList but that also not working, even not on List..

please suggest...

Upvotes: 1

Views: 680

Answers (1)

Murugan
Murugan

Reputation: 1451

You cannot specify the target type as Target = typeof(System.Object) in your code. Since an object of type 'Object' and 'Array' cannot be visualized.

From MSDN : You can write a custom visualizer for an object of any managed class except for Object or Array. Link : [http://msdn.microsoft.com/en-us/library/e2zc529c.aspx ][1]

For lists/IEnumerable :

Specify the target as Target = typeof(List<>) or Target = typeof(ObservableCollection<>)

For UserDefined Class :

Specify the target as Target = typeof(MyClass)

or

replace the Target with TargetTypeName = "MyNamespace.MyClass, MyNamespace"

This will work.

Upvotes: 2

Related Questions