.Net Debugging Tips & Tricks

Modified on 2011/11/18 15:48 by Mark Categorized as debugging, dotNet, tips and tricks

Use the DebuggerDisplay attribute

Add a private DebuggerDisplay property getter to your class, then apply the DebuggerDisplay attribute on the class to display it.

public sealed class MyObject{
    public string Foo { get; set; }
    public string Bar { get; set; }
    private string DebuggerDisplay {
        get { return string.Format("MyObject: {0} {1}", Foo, Bar); }

Using this pattern ensures you get a clean implementation that will speed up your debugging efforts. Make sure to avoid any property and methods that mutate the object state or throw exceptions.
For more info see DebuggerDisplay attribute best practices.