【问题标题】:How can I use a DebuggerDisplay attribute on an indexer class如何在索引器类上使用 DebuggerDisplay 属性
【发布时间】:2009-08-04 06:50:45
【问题描述】:

我正在尝试在索引器类上做这样的事情:

    [DebuggerDisplay("Debug: {_Items[index]}")]
    public override string this[byte index]

但是,当调试器评估字符串时,值字段中的消息是“索引在当前上下文中不存在”。

有没有办法使用 DebuggerDisplay 属性来控制索引器类中单个元素的显示??

【问题讨论】:

    标签: c# debugging indexer


    【解决方案1】:

    试试

    [DebuggerDisplay("Debug: {Items[{index}]}")]
    

    【讨论】:

      【解决方案2】:

      编辑:我真的对 OP 的问题没有信心。这是获取集合类型以在调试器中将其成员显示为列表的方法。

      将以下属性放在“数组或集合”的字段或属性上,也许它会检查 IList<T> 的实现?

      [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-23
        • 1970-01-01
        • 1970-01-01
        • 2013-06-16
        • 2018-09-02
        • 2013-06-22
        • 1970-01-01
        相关资源
        最近更新 更多