How do you find all implementations of the interface?

Suppose you have an interface defined in C #. What is the easiest way to find all classes that provide an interface implementation?

The brute force method should use Find Links in Visual Studio and manually view the results to separate usage from implementations, but for an interface in a large code base that is relatively referenced by relatively small implementations, this can be time consuming and error prone.

In Java, running code-based javadoc (using the -private option to enable private classes) will create a documentation page for the interface (e.g. Comparable ), which includes all the implementing classes for the interface, as well as any subinterfaces (although it does not include implementations of the classes of subinterfaces, they are relatively easy to determine by turning down to the listed subinterfaces). This is the kind of functionality I'm looking for, but with C # and Visual Studio.

+60
c # visual-studio resharper reflector
Mar 06 '09 at 20:53
source share
12 answers

(Change based on comment ...)

If you have ReSharper installed:

In Visual Studio, right-click the type name and select Go To Inheritor. Alternatively, select a type name, then go to ReSharper / View / Type Hierarchy to open a new tab. (In the menu you will see a key combination - this can change, so I explained how to find it :)

If you do not have ReSharper:

  • You can use the Reflector , which can very easily show you the entire hierarchy of types - just under the type name are extensible elements for basic types and derived types. Similar tools are available, such as ILSpy and dotPeek .
  • Buy ReSharper is a great tool :)
+31
Mar 06 '09 at 20:57
source share

You can click on the method name (definition in the interface or implementation in another class) and select "View Call Hierarchy". In the "Call hierarchy" window there is a folder "Implementations", where you can find all the locations of the implementation of the interface method.

+93
May 4 '11 at 1:13
source share

With Visual Studio 2010 +

Right-click a member method and select a view query hierarchy. Expand the "Implementations" folder. It lists all types that implement the interface to which the method belongs.

enter image description here

With Resharper 7

Right-click on the interface> Go to> Derived Symbols. Characters listed in bold are output directly from the interface. Bold characters are inferred from the superclass.

enter image description here

+13
Apr 24 '14 at 19:36
source share

Place the cursor in a class or interface type and

CTRL + F12

+11
May 26 '16 at 10:59
source share

For those using Visual Studio 2015, there is this amazing extension called Transition to Implementation . Give it a try.

Once you have installed the extension, you can simply right-click on any occurrence of the interface (for example, IUrlShortener) and click on the Go To Implementation menu. If you have only one class that implements the interface, clicking on the menu will lead you directly to the class. If you have more than one class that implements the interface, it will list all classes.

+9
Aug 30 '15 at 15:12
source share

For those using Visual Studio 2015, install Visual Studio 2015 Update 1 RC. From Visual Studio Blog :

Today we released Visual Studio 2015 Update 1 RC, which is based on the CTP update we released three weeks ago. In addition to the features introduced in the CTP, as described here, the Release Candidate includes the following:

  • Go to implementation . A feature that many of you are waiting for: just right-click on an interface or abstract method and select this command to proceed with the implementation.
+6
Feb 24 '16 at 0:24
source share

I do not think this functionality is built into VS, but IIRC Resharper has it.

+2
Mar 06 '09 at 20:57
source share

You can search for a regular expression for an interface.

 :(\ *[^},]+,)*\ *IMyInterfaceName 

CTRL + SHIFT + F launches the following window:

Visual studio screenshots

+2
Oct. 20 '14 at 11:18
source share

I prefer the option "Navigate to ...". Hover over a function call, try the following:

Keyboard shortcut:

  1. Ctrl +, (Ctrl + comma)

Menu:

  1. Edit menu
  2. Click "Go to ..."

Benefits:

  • All links like "Find all links" do not appear
  • Shows the "type" of the implementation, so it will notice which interface you have
+2
Apr 17 '15 at 16:25
source share

Use Shift + F12 to show all links, including definitions.

+1
Oct 17 '14 at 19:47
source share

If you are using resharper ALT + END , a shortcut can help find all of the following.

0
Mar 06 '09 at 20:57
source share

I heard say (no experience myself) that Doxygen for .Net is like Javadoc for Java.

0
Mar 06 '09 at 21:00
source share



All Articles