6

Is there an extension for visual studio that would allow to do Go to Definition from a method and have it navigate straight to the concrete implementation instead of interface? Most of my code is inteface based and right if i do Go to definition it goes straight to the interface which makes sense, be nice to have Go to Concrete implementation..Thankx

user282807
  • 905
  • 3
  • 13
  • 26

5 Answers5

4

If you using resharper it offers go to implementation and if there are different implementations you can choose among different implementation.

Also in the visual studio you can use find all references, method icon is different from calls, Also you can navigate on them by F8.

And in the visual studio 2010 or later you can use "ctrl"+"," and write the name in the window that appears in this action, then select among shown candidates, in this case you allowed to write abbreviations, ....

Saeed Amiri
  • 22,252
  • 5
  • 45
  • 83
2

This isn't possible, as the IDE doesn't know which implementation is used when you rightclick a method. Given this example, which method should the IDE navigate to:

public interface IGreeterService
{
  string Greet(string person);
}

public class EnglishGreeterService : IGreeterService
{
  string Greet(string person)
  {
    return "Hello, " + person + ".";
  }
}

public class GermanGreeterService : IGreeterService
{
  string Greet(string person)
  {
    return "Guten Tag, " + person + ".";
  }
}

public class PersonGreeter
{
  private readonly IGreeterService _Service;

  public PersonGreeter(IGreeterService service)
  {
    _Service = service;
  }

  public void SayHallo()
  {
    _Service.Greet("user282807");
  }
}

It is impossible to know which implementation is used in the class PersonGreeter; that's the point of interfaces, so you don't rely on a specific implementation. Of course, this can be tiresome while developing.

Femaref
  • 60,705
  • 7
  • 138
  • 176
  • 2
    It can offer implementations. – Saeed Amiri Nov 20 '10 at 20:38
  • Of course it could, but that would contradict the name "Go to definition". The method is defined in the interface, that's why it is shown. – Femaref Nov 20 '10 at 20:40
  • I agree that's why i mentioned Go to Implementation and if there are more than one, atleast be able to choose, example right click on method then context menu that has the implementation sources to navigate to. – user282807 Nov 21 '10 at 01:48
  • 1
    If there is only one implementation, more often than not, I would like it to go to that, and the IDE could be designed to do that. – Bradley Thomas Aug 26 '13 at 18:48
1

If you are using CodeRush then you can use Ctrl + Alt + N to bring up the navigation choices and go to Implementations

Michael Prewecki
  • 2,064
  • 4
  • 16
  • 28
0

Hi i dont know can it be usefull or not but i use Visual Assist "Find all references"

Sanja Melnichuk
  • 3,465
  • 3
  • 25
  • 46
0

Visual Assist includes interface implementations in its alt+g (go to) command as of Build 1836 (November 10, 2010).

sean e
  • 11,792
  • 3
  • 44
  • 56