Joe White’s Blog

Life, .NET, and Cats


ReSharper, day 12: Type Hierarchy view

Welcome to day 12 of my 31 Days of ReSharper.

Today’s topic is a feature I’ve spent so long wishing for that I can never remember it actually exists: the Type Hierarchy view, accessed via Ctrl+Alt+H.

ReSharper's Type Hierarchy, showing the class hierarchy for System.Windows.Forms.Form

If you press Ctrl+Alt+H while the cursor is over a type name, it will pop up the Type Hierarchy window, showing the ancestors and immediate descendants of that type. (Like all the other ReSharper windows, it’s dockable.) You can expand the tree to show lower-level descendants as well. If you’ve got a complicated type hierarchy that you always access through an interface, you can see the whole tree just by cursoring to the interface and pressing Ctrl+Alt+H.

You can right-click on a node and select “Base on this”, which will re-do the tree as if you had pressed Ctrl+Alt+H on that type. If you do this on a class’s parent type, it will open up more classes in the tree (because you only see the based-on class’s direct ancestors; but if you base on one of those ancestors, you see all of its other descendants in the tree as well). The current based-on class is shown in bold.

ReSharper's Type Hierarchy, showing the class hierarchy for System.Windows.Forms.ContainerControl

I think it’s really cool that “Base on this” remembers which types you already had expanded and which were collapsed, and leaves them that way.

The Type Hierarchy window also has a couple of alternative views, accessible through the little object-graph-looking buttons on the right side of the toolbar. Besides the main hierarchy view, there’s a view that shows just the descendants, which isn’t that interesting; it’s just the main hierarchy view with less indentation.

The third view shows just the supertypes. The supertype view is interesting because it inverts the tree (parents are shown as sub-nodes), so it can show the interfaces a class implements, as well as its parent classes.

ReSharper's Type Hierarchy, showing the supertypes of System.Windows.Forms.Form

The right-click context menu, besides “Base on this”, has Find Usages and a Refactor submenu. So if you’re looking at a type hierarchy and feel a sudden need to rename one of the classes in it, you can. (It’s smart enough to gray out things like Rename for classes you don’t have the source code for.)

Finally, you can double-click a type in the tree to jump to it in code. (Although it uses the klunky Class Browser instead of Visual Studio’s new “[from metadata]” code view for types you don’t have the source code for.)

There are no responses to “ReSharper, day 12: Type Hierarchy view” yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Joe White's Blog copyright © 2004-2011. Portions of the site layout use Yahoo! YUI Reset, Fonts, and Grids.
Proudly powered by WordPress. Entries (RSS) and Comments (RSS). Privacy policy