.NET debugging made easier

Not sure about you but I was not aware of the existence of the DebuggerStepThroughAttribute. Debugging code can be difficult at times and any tool or mechanism that can ease this pain is always welcome.

As far as the CLR is concerned, there is no semantic attached to this attribute. However Visual Studio does not step through methods or classes that are decorated with this attribute. Although you could still use breakpoints in those methods or classes, they are never hit.

And here is how breakpoints would look in Visual Studio 2008:

 

This attribute can be applied to methods, property accessors, classes and structs. I found it to be extremely useful when I wanted to step through a method without first stepping through all property accessors used as parameters or the source instance of the method. In the example below, a.Value and b.Value are not stepped through when pressing F11 in Visual Studio. It is only the Add method that is fully debugged:

var a = new SomeValue(10);

var b = new SomeValue(150);

...

Add(a.Value, a.Value);

class SomeValue

{

  ...

  public int Value

  {

    [DebuggerStepThrough]

    get { return value; }

  }

}

Enjoy!