views:

298

answers:

5

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

The brute force method would be to use "Find References" in Visual Studio and manually look through the results to separate out the usages from the implementations, but for an interface in a large codebase that is heavily referenced with relatively few implementations, this can be time consuming and error prone.

In Java, running javadoc on the codebase (using the -private option to include private classes) would generate a documentation page for the interface (e.g. Comparable) that includes all implementing classes for the interface as well as any subinterfaces (though it doesn't include implementing classes of the subinterfaces, these are relatively easy to determine by drilling down into the listed subinterfaces). It's this functionality that I'm looking for but with C# and Visual Studio.

+1  A: 

I don't think this functionality is inbuilt into VS but IIRC Resharper has this.

Mohit Chakraborty
A: 

If you use resharper ALT + END shortcut might help to find all Inheritors.

Canavar
+3  A: 

(Edit based on comment...)

If you have ReSharper installed:

In Visual Studio, right click on the type name and choose "Go to Inheritor". Alternatively, select the type name, then go to ReSharper/View/Type Hierarchy to open up a new tab. (The menu will show you the keyboard shortcut - this can vary, which is why I explained how to find it :)

If you don't have ReSharper:

  • You can use Reflector, which is able to show you all the type hierarchy very easily - just under the type name are expandable items for base types and derived types.
  • Buy ReSharper - it's a great tool :)
Jon Skeet
That's a ReSharper feature.
John Price
ReSharper is already on my list of requests; I figured it probably had the capability, but alas, I don't yet have it. Reflector allowed me to get the answer to my specific search, though it was a bit of a pain to find and add all the assemblies that reference the one with the interface definition!
iammichael
A: 

try searching for implements [interface] that should only give you implementations and not usages.

Andrew Clark
A: 

I've heard tell (no experience myself) that Doxygen is to .Net as as javadoc is to java.

overslacked