Home How to enhance debugging in Visual Studio with just one simple step
Post
Cancel

How to enhance debugging in Visual Studio with just one simple step

During the debugging session, I always had problems with complex structures. Preview most interesting properties were irritating, we need to expand a variable. In most cases, I tried to override ToString method. But it isn’t always possible. Default tooltip is useless. Just look on it:

Adding an attribute

Probably You won’t believe me, but a few years ago, in .NET 2.0 times, Microsoft introduced DebuggerDisplayAttribute, which is very useful. Just add it like below:

1
2
3
4
5
6
7
[DebuggerDisplay("Range=<{RangeStart}; {RangeEnd})")]
class Range
{
    public int Start;
    public int End;
    //Other stuff
}

Now, tooltip looks great. Moreover, your class doesn’t change at all. Just check it out:

More awesome stuff

Another great attribute is DebuggerBrowsableAttribute and DebuggerTypeProxyAttribute. Just take a look on MSDN to find out more.

This post is licensed under CC BY 4.0 by the author.