Visual Studio: How do I show all classes inherited from a base class?

Viewed 94655

In Visual Studio, How do I show all classes inherited from a base class?

For example, in ASP.NET MVC there are several 'ActionResult' types -- and they all inherit from / implement the base class ActionResult.

It looks like unless you just 'know' that View and Json are valid ActionResult types, there is no way you can easily find this information out.

Please prove me wrong.

Is there something in the object browser that makes this easy to find out?

I'm even up for suggestions of tools outside of Visual Studio to discover this information about various classes. For example: is there something in Resharper that will help me out?

19 Answers

You don't necessarily need Reflector for this - Visual Studio's "Class Diagram" view will let you easily find all derived classes for a particular class as well. Right click on the class in "Class View" and choose "View Class Diagram". If the diagram doesn't show the level of detail you want for the hierarchy, right click on the box for the class in the diagram, and choose "Show Derived Classes".

Might not be as direct as ReSharper, but it's an option if you don't have R# already.

Unfortunately, I'm not certain which particular versions of Visual Studio have it.

Sure, Resharper can do this. And much more.

Just right click on type name in any place and choose "Go To Inheritor" in context menu. "Go To Inheritor" can be also applied to method for navigating to overrides and an interface method's implementations. For an interface you could call "Find Usages Advanced" again, just right click) where to find all extendings and implementations. For a type - derived types. And my favorite feature - click with holding Control on any type/method for navigating to its declaration.

I think it's a must-have tool for .net developers.


In Resharper 9.2, on any type in source code, rt-click "Find Usage Advanced", select Find="Derived" and Scope="Solutions and Libraries".
For example, to find all inheritors (both in the library and your code) of some base class in an included DLL from any vendor, declare a variable in your code with that base class. Then right-click on that base class name you just typed.

For Framework classes, I use the MSDN Library. The Inheritance Hierarchy section goes in both directions. Admittedly not much help for some 3d party libraries, though.

2020 update:

You can use Visual Studio's Code Maps which works pretty fine.

Simply right click on the class and navigate to:
Code Map > Show Related Items on Code Map > Show All Derived Types

enter image description here

Note:

  • This feature is available only on the Enterprise edition of the Visual Studio, and if you don't have, you can get it for free by downloading the Enterprise Preview version from here.
  • Or you might just ask anyone from your team share the code map with this feature if they have that edition.

P.S. It really worths to keep the Enterprise version (or at least the Preview version of it) in your machine, as it has bunch of really useful tools that are not included in the other editions.

Related