tags:

views:

320

answers:

4

Is it possible to hide fields and/or properties from showing up in the debugger watch window? See, we've got a class here with over 50 private fields, most of which are exposed through public properties. This means we're seeing a duplication of a large number of data in the watch window listing.

Is there any means of controlling this?

A: 

You could use autos instead of locals or use watches and only watch the variables of interest...

Arnshea
+8  A: 

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.

Andrew Hare
+1 for the in depth, and yet still succinct, answer. Man I love this site.
ee
+3  A: 

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.

Martin Peck
+1 for the related tips.
ee
+1  A: 

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.

fung