Ever been stepping through code using F10 and F11 and forget to step over something that you did not want to step into? Like a whole series of Get/Set calls on a bunch of properties for a class that you know is fine?
You can control what the debugger steps into by using method attributes and decorations. Using these you can essentially make parts of your code invisible to the debugger.
The first one I want to discuss is the <DebuggerStepThroughAttribute>. Using this attribute will prevent the debugger from stepping into the code it is applied to.
VB.NET
Private ReadOnly Property LastName() as String
<DebuggerStepThroughAttribute()> _
Get
LastName = m_LastName
End Get
End Property
C#
private string LastName
{
[DebuggerStepThroughAttribute()]
get
{
LastName = m_LastName;
}
}
With the above you can still set a breakpoint inside the methods and execution will stop when the breakpoint is reached. If you want to make the code completely invisible to the debugger including not being able to set breakpoints then use the second attribute.
<DebuggerHiddenAttribute>, This attribute will essentially hide the methods it is applied to from the debugger entirely.
VB.NET
Private ReadOnly Property LastName() as String
<DebuggerHiddenAttribute()> _
Get
LastName = m_LastName
End Get
End Property
C#
private string LastName
{
[DebuggerHiddenAttribute()]
get
{
LastName = m_LastName;
}
}
Note that in order to get the debugger to honor these attributes you need to turn off the "Just my Code" option in Tools|Options|Debugging Options.
Oh, and finally you need to import the System.Diagnostics namespace for this to work at all.
Hope this helps, I know I use it a lot, once I knew it existed.
Cheers,
Robert Porter