Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding fields from the debugger

Tags:

c#

debugging

Try this attribute:

 [DebuggerBrowsable(DebuggerBrowsableState.Never)]

Use it to hide your backing fields by placing the attribute above the field declaration like this:

class Foo
{
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    int bar;  // this one will be hidden
    int baz;  // but this one will be visible like normal
}

Keep in mind that the DebuggerBrowsableState enumeration has two other members:

Collapsed: Collapses the element in the debugger.
RootHidden: This shows child elements of a collection but hides the root element itself.


Check out the DebuggerBrowsableAttribute:

http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerbrowsableattribute.aspx

In fact, this article has some very useful tips for this area:

http://msdn.microsoft.com/en-us/magazine/cc163974.aspx

You might find that using a DebuggerTypeProxy makes more sense. This allows you to provide a "custom view" of the type.


The DebuggerBrowsableAttribute is covered in this other SO question. If you're doing C# heavily then it's a good question to read up on.


I know this is old but you would be much better off with using DebuggerTypeProxy http://msdn.microsoft.com/en-us/library/d8eyd8zc.aspx

this way you don't have to modify your class with ugly attributes and the extra benefit is that you can always look at the real type if you do in fact need to have a look at one of those "hidden" fields.