Is there a way to navigate to real implementation of method behind an interface?

后端 未结 15 1438
攒了一身酷
攒了一身酷 2020-12-07 08:58

In Visual Studio, when you right-click a method call, you go to the implementation of that method inside a class except if you access this method through an interface: in th

相关标签:
15条回答
  • 2020-12-07 09:36

    Depending on the version of Visual Studio that you have, I'll say conditionally "yes."

    I'm currently operating on Ultimate, and don't have other versions to verify this. That said, within Ultimate, you can use the Architecture Explorer to find implementations. It's a little more involved than the right click method, but here's how it works.

    • Go to View->Architecture Explorer (or CTRL-W, N)
    • Click on Class View and find the namespace that contains your interface in the list that opens.
    • To the right of the namespace list, is a vertical button that says Types. Click this
    • Select Interfaces
    • Choose your interface from the list
    • A vertical button that says Members will then appear to the right. Click that button
    • Choose Implemented by (under Inbound Navigation) and that will provide a list of implementations of your interface.
    • Double clicking on the implementation will take you to the class.
    0 讨论(0)
  • 2020-12-07 09:36

    Within 2012 Ultimate, you can search the interface in solution explorer. Right-click the interface and choose "Derived Types", the implemented classes will shown in solution explorer. Not sure if it works in express.

    0 讨论(0)
  • 2020-12-07 09:40

    I do the following:

    1) Right click on the method and click "View call hierarchy" (or shortcut Ctrl+K, Ctrl+T)

    2) Expand the "Implements x" folder which will then show you all the implementations of that method. Click on one to go there.

    Relatively quick and easy. Annoyingly though there doesn't seem to be an equivalent for the interface itself.


    update: as of Visual Studio 2015 update 1, right click on a method and select go to implementation. You can also map it to keyboard shortcut via Tools > Options > Environment > Keyboard and search for Edit.GoToImplementation command. The default shortcut is Ctrl+F12. (F12 will navigate to the interface).


    0 讨论(0)
  • 2020-12-07 09:43

    I created a free extension for Visual Studio 2010 and Visual Studio 2012 called Inheritance Margin to provide this specific feature, as well as give a clear indication when a method implements an interface method due to a signature match. In the current version, you can right click on any glyph to get a menu of items to navigate to.

    Inheritance Margin - Visual Studio Gallery


    (source: microsoft.com)

    0 讨论(0)
  • 2020-12-07 09:43

    For people who use Resharper, pressing CTRL + F12 will make you go directly to the class method!

    0 讨论(0)
  • 2020-12-07 09:44

    Visual Studio can only tell you where it is referenced, but this may be too coarse.

    There are other tools that can tell you more about the structure of your application, including which class implements which interface, which method overrules which other method, and so on. I personally prefer using Understand For C/C++.

    0 讨论(0)
提交回复
热议问题