apocalypse
apocalypse

Reputation: 5884

Show custom indexer in debugger

I have sample indexer like ths:

public byte this[long pIndex]
{
    get
    {
        // return something
    }
}

How to tell Visual Studio to display all elements from this indexer in debugger? And how to tell about pIndex range?

Upvotes: 1

Views: 239

Answers (2)

alex
alex

Reputation: 12654

You can implement IEnumerable interface in your class. Debugger can use it to get all the items and display them the same way it displays linq expression results.

If you want to see the single element, you can add a watch expression this[123]

Upvotes: 3

Eilon
Eilon

Reputation: 25704

Try using a Debugger Display Attribute, as described here:

Try doing something like this:

[DebuggerDisplay("{this[0]}")]
public byte this[long pIndex]
{
    get
    {
        // return something
    }
}

Upvotes: 1

Related Questions