Cameron Peters
Cameron Peters

Reputation: 2562

How can I use a DebuggerDisplay attribute on an indexer class

I am trying to do something like this on an indexer class:

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

However, when the debugger evaluates the string, the message in the value field is "index does not exist in the current context".

Is there some way to use the DebuggerDisplay attribute to control the display of a single element within an indexer class??

Upvotes: 1

Views: 1183

Answers (2)

amazedsaint
amazedsaint

Reputation: 7642

Try

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

Upvotes: 3

Sam Harwell
Sam Harwell

Reputation: 99869

Edit: I really am not confident of the OP's question. This is how you can get a collection type to show its members as a list in the debugger.

Place the following attribute on a field or property that is "an array or collection", perhaps it checks for an implementation of IList<T>?

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]

Upvotes: 1

Related Questions