从调试器隐藏字段
是否可以隐藏字段和/或属性以在调试器监视窗口中显示?看到,我们在这里有一个50多个私人领域的课程,其中大部分是通过公共属性公开的。这意味着我们在观看窗口列表中看到大量数据的重复。
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.
有没有办法控制这个?
尝试此属性:
[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
}
可以看到,请记住, code> DebuggerBrowsableState 枚举还有另外两个成员:
Keep in mind that the DebuggerBrowsableState
enumeration has two other members:
折叠:
折叠调试器中的元素。
RootHidden:
显示集合的子元素,但隐藏根元素本身。
Collapsed:
Collapses the element in the debugger.RootHidden:
This shows child elements of a collection but hides the root element itself.