This is a mirror of official site: http://jasper-net.blogspot.com/

Why override ToString()? Use DebuggerDisplayAttribute instead

| Thursday, April 7, 2011
Debugging and Runtime Inspection
The Visual Studio 2010 debugger is an awesome tool, no doubt about it. It's likely the most powerful and capable debugger ever developed for Windows or any other platform. And yet, there are times when you wish it 'knew' or exposed more detail. When you're debugging a runtime instance of your application or inspecting a mini-dump to gain insight into the state of your application, often the most useful details are the values of the variables that characterize the state of your app at that particular moment. Or if you unwind a stack trace and wish to see the state of objects prior to the call that failed, you may be disappointed by the lack of simple exposure to object state displayed in the hover-tooltips by default. 

When you're inspecting the state of an application while debugging and drilling down on your own type instances, or inspecting 3rd party assembly/DLL exposed types, the experience is likely a bit less than intuitive or optimal.

Imagine this situation, you've definately encountered it but probably never realized you had any power over the situation... You're stopped on a breakpoint in the debugger and using the mouse to hover over variables in the debugger - you're depending on the Visual Studio hover-tooltips to inspect various instance or static variable values in order to build a mental image of the state of your application.

Often times you wait for the popup window, then you start clicking on the '+' signs to dig deeper, but then your mouse cursor drifts off the tolerance gap of Visual Studio and the inspection pane disappears! Or you get lucky and after clicking enough you get to inspect the value of properties within an array of object instances, or subordinate to the particular object you happen to be inspecting.  But you have to click a whole-bunch-of-more-times to inspect the other instances of your type in a collection/array...

With simple native types VS quickly displays useful runtime value information. If you hover the mouse over an int or a double you will be quickly presented with the instance value. As well, with complex types that Visual Studio is already aware of you will see similarly useful inspection details exposed.

Read more: SoulTech

Posted via email from Jasper-net

0 comments: