从调试器隐藏字段 [英] Hiding fields from the debugger

查看:170
本文介绍了从调试器隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以隐藏字段和/或属性以在调试器监视窗口中显示?看到,我们在这里有一个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.

这篇关于从调试器隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆