Reputation: 3372
When debugging there are various Variable windows (autos, locals, watch) containing columns Name,Value,Type. The value often seems to show an object's class name. In specific cases I would like to show something more meaningful based on the properties of the class instance.
As a specific example, for CodeTypeReference I'd like to see a text representation of the type referenced (where valid) based on the BaseType string or ArrayElementType value, rather than seeing "System.CodeDom.CodeTypeReferenceExpression".
Visualizers seem to offer separate dialog windows, rather than a way to populate the value column.
Data tips are per variable rather than per type.
The closest thing seems to be the DebuggerTypeProxyAttribute in which case I guess I'm asking "Is it possible to apply an attribute to somebody else's class ?"
I'm mainly dealing with Visual Studio 2010 although a Visual Studio 2008 answer would be useful.
Upvotes: 1
Views: 2227
Reputation: 2627
Yes you can apply DebuggerTypeProxyAttribute to types you don't own (unless they are private) as explained in my answer to a similar question here
Upvotes: 0
Reputation: 11827
Yes, there are two ways you can accomplish this:
By using OzCode (previously BugAid for Visual Studio), a commercial tool that I created, you can simply star properties/fields on your type, and have those appear in the Value column on any type, whether it is 3rd party or not.
You can change your autoexp.cs file, and apply either the DebuggerDisplayAttribute or the DebuggerTypeProxyAttribute to 3rd party types, as described in my answer on a similar question. For example, this is how you would apply the DebuggerDisplayAttribute to System.Drawing.Pen: [assembly: DebuggerDisplay(@"\{Color = {color}}", Target = typeof(Pen))]
This answer applies to both VS2008 and VS2010.
Upvotes: 7
Reputation: 10347
You can override the ToString method for your own classes. The Value is usually just a call to ToString, and if not overridden, this shows the type.
Update: For classes you do not have the code for, I cannot provide a valuable answer rather than you could wrap the classes ( inherit from ), but that is, hm, strange to be polite ( IMHO ).
Upvotes: 1