Visual Studio Debug View (value column / hover pop up tooltip) custom content: DebuggerDisplay
-
Hi, in the Visual Studio Debug View value column (same as the debug mode hover pop up tooltip) I find it inefficient that for variables of compound types only the type name is displayed and to get to any state information I need to expand the display (click on plus icon). I found an example image here: http://www.davidhayden.com/photos/defaultdebuggervisualizer.jpg I'd love to control what goes into the string currently displaying the type name, like a function or property that, if implemented, overrides the default debugger class type display. I.e. in the image above I'd want to replace the "{Ecommerce.Shoppingcart}" with the output of Ecommerce.Shoppingcart.ToString(). Any idea if and how this is possible? Thanks, Ingmar
modified on Monday, November 10, 2008 3:00 PM
-
Hi, in the Visual Studio Debug View value column (same as the debug mode hover pop up tooltip) I find it inefficient that for variables of compound types only the type name is displayed and to get to any state information I need to expand the display (click on plus icon). I found an example image here: http://www.davidhayden.com/photos/defaultdebuggervisualizer.jpg I'd love to control what goes into the string currently displaying the type name, like a function or property that, if implemented, overrides the default debugger class type display. I.e. in the image above I'd want to replace the "{Ecommerce.Shoppingcart}" with the output of Ecommerce.Shoppingcart.ToString(). Any idea if and how this is possible? Thanks, Ingmar
modified on Monday, November 10, 2008 3:00 PM
Couldn't you do items(0).tostring in the watch window? Or you could override the .tostring and loop the items with a debug.writeline with how you want the data formated.
Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison
-
Hi, in the Visual Studio Debug View value column (same as the debug mode hover pop up tooltip) I find it inefficient that for variables of compound types only the type name is displayed and to get to any state information I need to expand the display (click on plus icon). I found an example image here: http://www.davidhayden.com/photos/defaultdebuggervisualizer.jpg I'd love to control what goes into the string currently displaying the type name, like a function or property that, if implemented, overrides the default debugger class type display. I.e. in the image above I'd want to replace the "{Ecommerce.Shoppingcart}" with the output of Ecommerce.Shoppingcart.ToString(). Any idea if and how this is possible? Thanks, Ingmar
modified on Monday, November 10, 2008 3:00 PM
If you're using .NET 2.0 or later take a look at the DebuggerDisplay[^] attribute. Here are some additional resources as well: Using DebuggerDisplay Attribute[^] Enhancing Debugging with the Debugger Display Attributes[^]
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
Couldn't you do items(0).tostring in the watch window? Or you could override the .tostring and loop the items with a debug.writeline with how you want the data formated.
Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison
> Couldn't you do items(0).tostring in the watch window? > Or [...] override the .tostring and loop the items with a debug.writeline [...] Of course I could, but that is equally inefficient, i.e. I need to do stuff to get to the state information. What I want is to sit down once (per custom type), write a useful concise state to string conversion, and then have it be used automatically by Visual Studio whenever the matching variables are in a debug view.
-
If you're using .NET 2.0 or later take a look at the DebuggerDisplay[^] attribute. Here are some additional resources as well: Using DebuggerDisplay Attribute[^] Enhancing Debugging with the Debugger Display Attributes[^]
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
Thanks Scott, this gets pretty close. However, C# and VB seem to behave differently. The documentation talks by default about the C# solution and how ToString() can be used to fill the debugger value field. That is exactly what I wanted. But in Visual Studio 2005 and VB.NET ToString() is by default a function, and unfortunately < DebuggerDisplay("{ToString}") > is rejected. Only if I use a property does it work, so I have to make a DbgStr() property that calls ToString(), a little ugly but works.
-
Thanks Scott, this gets pretty close. However, C# and VB seem to behave differently. The documentation talks by default about the C# solution and how ToString() can be used to fill the debugger value field. That is exactly what I wanted. But in Visual Studio 2005 and VB.NET ToString() is by default a function, and unfortunately < DebuggerDisplay("{ToString}") > is rejected. Only if I use a property does it work, so I have to make a DbgStr() property that calls ToString(), a little ugly but works.
Unless your ToString method contains complex logic and formatting rules, you could specify it directly in the attribute as
<DebuggerDisplay("ProperyOne = {PropertyOne}, PropertyTwo = {PropertyTwo}")>
. Also, try specifying it like this:<DebuggerDisplay("{ToString**()**}")>
.Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
Hi, in the Visual Studio Debug View value column (same as the debug mode hover pop up tooltip) I find it inefficient that for variables of compound types only the type name is displayed and to get to any state information I need to expand the display (click on plus icon). I found an example image here: http://www.davidhayden.com/photos/defaultdebuggervisualizer.jpg I'd love to control what goes into the string currently displaying the type name, like a function or property that, if implemented, overrides the default debugger class type display. I.e. in the image above I'd want to replace the "{Ecommerce.Shoppingcart}" with the output of Ecommerce.Shoppingcart.ToString(). Any idea if and how this is possible? Thanks, Ingmar
modified on Monday, November 10, 2008 3:00 PM
You will want to look into adding custom AutoExpand rules. A search for AutoExp.dat should get you the info you need. Note: On my system, AutoExp.data is located here: C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Packages\Debugger