I am always looking for new features in the Visual Studio IDE that help streamline the everyday coding and debugging tasks that we do. At PDC, I attended a good session on productivity enhancements in the Visual Studio 2005 IDE. (Thanks to Anson Horton for the content.)
Here are just a few of the new features that I’m sure I’ll be using.
DebuggerStepThrough
When you’re stepping through lines of code in the debugger, many times you want to step INTO a method call. However, if it has some parameter arguments that are themselves method or constructor calls, you end up stepping into those first. Visual C++ 6 had a feature that I really liked, and miss now – you could right click on the function call, and “Step Into “. VS.NET IDEs do not have that, so I’ve gotten good in the past few years at F11, Shift+F11, F11, Shift+F11, …
There is now a solution: The DebuggerStepThrough attribute.
You can apply it to any method or constructor.
using System.Diagnostics;
[DebuggerStepThrough()]
public Person( string name, string phone )
…
// Now the debugger will step straight into the CallPerson method
p.CallPerson(new Person(“dan”, “5551212”));
Unfortunately, I couldn’t get this working on a property. Compiler error says I can only apply this attribute to class, struct, constructor, or method. I wonder why they didn’t extend this to properties?
Debugger Tool Tips
In the last few versions of the IDE, the debugger has displayed tool tips when you mouse-over a variable. The bummer is, for objects, the tooltip information is usually not that helpful – it just tells you the type of the object.
“ConsoleApp1.Person” — not a lot of info here.
Using another attribute, DebuggerDisplay, you can control what the debugger will show in the tool tips for a class
[DebuggerDisplay( “Name={name}, Phone={phone}” )]
Now, in the debugger, you can probably guess what you’ll see:
Name=”Dan”, Phone=”5551212″
Simple things like this prevent you from having to right click, quickwatch, and drill down into the object to see relevant data. This formatting is also used for the top level display in the autos and watch windows.
In previous versions of the IDE, you could control this display in the autoexp.dat (c++), or autoexp.cs (c#) files. You can still do this for classes that you don’t have source code for.
Find this file in \Common7\Packages\Debugger\Visualizers\Original
DebuggerBrowsable
Finally, when you expand the debugger display for a class with properties, you will usually see the properties, and then the private fields, which repeat the same data from the properties.
Name “Dan”
name “Dan”
Phone “5551212”
phone “5551212”
Use the DebuggerBrowsable attribute to control what data is displayed when drilling down into a class.
[DebuggerBrowsable( DebuggerBrowsableState.Never )]
public string Name
…
Now you’ll only see the field:
name “Dan”
Visualizers Getting in the Way?
A very cool feature of VS 2005 is visualizers. You’ll probably see them in your first debug session in the new IDE. They are the expanding tool tip windows that show hierarchies of classes, structs, data that is in the variable you’re watching.
Well, the more you expand, the more code you obscure behind the “tree” windows.
Want to quickly check something in the code that’s behind all those windows?
Hold down CTRL !! The popup windows become transparent — very cool.