11

I work with a codebase where several classes implement an indexer:

public double this[int i, int j]
{
    get { return ...; }
    set { ...; }
}

When I stumble over code like foo[1,2] = 3 in visual Studio 2008, I frequently want to
right-click / "go to definition", i.e. show the above definition in the visual studio editor window.

For normal properties or methods this works without problems:
foo.bar = 3, right-click / "go to definition" takes me to the source code for foo.bar.
For overloaded + or == this works as well.
However with the indexer this does not seem to work. Is there any way to accomplish this?

(I cannot even search for the string "this[" in the appropriate source file, since the same syntax may be used throughout the class to access the indexer. I always have to scroll trough all the methods and properties in the dropdown list for this file)

HugoRune
  • 13,157
  • 7
  • 69
  • 144
  • 1
    FYI, this is called an indexer, and is not an overloaded operator. – Erik Funkenbusch Aug 29 '12 at 15:43
  • Thanks, I was always wondering what to call this; fixed – HugoRune Aug 29 '12 at 15:52
  • If you have so many methods, and your class is so large, that finding this is really *that* hard you should probably look into making it a bit smaller. Move sections of the functionality to other classes so that each class is more manageable. – Servy Aug 29 '12 at 16:03
  • 2
    it is not my framework to change, at the moment I am just trying to understand it. – HugoRune Aug 29 '12 at 16:25

3 Answers3

4

This doesn't really help with 2008 of course, but in 2010 and above they have "fixed" this with the Navigate To command (ctrl+, in the C# keyboard layout). Where you can enter this to show a list of indexers in the current solution where you can double-click the one you want to navigate to.

+1 for Resharper which seems to work fine with pressing F12 when you caret is within an indexer usage.

Heinzi
  • 167,459
  • 57
  • 363
  • 519
Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98
  • 1
    Hint: this works either when you highlight the whole expression `map[key]`, or put the cursor just after the closing `]`. Elsewhere and you're likely to go to one of the variable's declarations! (VS2010, Reshaper) – Nigel Touch Dec 11 '14 at 19:13
2

You can install Resharper who give you this functionality, Tool Box productivity don't give this functionality

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
0

Your best bet will probably be to go to the definition of foo and see what that class is indexing.