How do you quickly find the implementation(s) of an interface's method?

C#Visual StudioIntellisenseInterface Implementation

C# Problem Overview


Is there a quick way to find all of the implementations of, not references to, an interface's method/property/etc? Here's some sample code:

public class SomeClass : IBaseClass
{
  public Int32 GetInt()
  {
     return 1;
  }
}

public interface IBaseClass
{
  public Int32 GetInt();
}

public class SomeOtherClass
{
  IBaseClass _someClass;
  private TestMethod()
  {
    _someClass = new SomeClass();
    _someClass.GetInt();
  }
}

I want to quickly get to SomeClass.GetInt() while reviewing SomeOtherClass.TestMethod(). If I right click on _someClass.GetInt() and click 'Go To Definition', it takes me to the interface. If I click 'Find All References', I could potentially see a list of all uses ... not just the classes that implement the GetInt() method.

Is there a faster way to find this? Any tips from other developers? We are using D.I. for most of our dependencies, which means that tracing through deeply nested code takes forever.

C# Solutions


Solution 1 - C#

Since I don't like to use the mouse while coding, I usually

  • move the cursor over the method
  • type ctrl+k clrl+t to open the Call Hierarchy window
  • move down to Implements node.
  • type Return to go to the selected implementation

AFAIK this is the quickest way to find the implementation of a method, without ReSharper.

(By the way: you can use the same system to move from a class method implementation to the corresponding interface declaration: just select the root)

Solution 2 - C#

Alt-End will do this in ReSharper, I believe.

Solution 3 - C#

Without ReSharper the best way to do this is:

Find in files (Ctrl+Shift+F) Find What: "class*ISomeClass" Find Options: "Use Wildcards"

This will find all implementation and than you can search for your function in a concrete implementation.

Solution 4 - C#

Solution 5 - C#

If your interface is in the same library as your concrete model that you'll typically want to navigate to, you could add a 'using alias' to the concrete object. 'Usings' are helpers anyhow, and this helps.

using System;
using PrimaryImplementation = YourNamespace.YourConcreteObject;


public interface IYourInterface{

}

When you're taken to the interface, you have a quick (and dirty) way of getting to the primary implementation of your interface. F12->F12!

Solution 6 - C#

R# has a Go to Implementation option on the pop-up menu, which is really handy for that.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBeep beepView Question on Stackoverflow
Solution 1 - C#Arialdo MartiniView Answer on Stackoverflow
Solution 2 - C#lanceView Answer on Stackoverflow
Solution 3 - C#ZhenyaView Answer on Stackoverflow
Solution 4 - C#Robert IvancView Answer on Stackoverflow
Solution 5 - C#BlackjacketMackView Answer on Stackoverflow
Solution 6 - C#Brian RasmussenView Answer on Stackoverflow