Visual Studio 2010 Call Hierarchy
Visual Studio 2010 includes a number of navigation enhancements over previous versions. In this article, the Call Hierarchy feature is described. This allows developers to quickly and recursively browse calls made to and from a member.
Visual Studio 2010 introduces several new tools that permit easier navigation and understanding of the structure of your source code. One of the new features is the Call Hierarchy. It allows you to select a member, such as a method, property or constructor, and view two structured lists that relate to it. The first shows of all of the other members in the code that call the selected item and the second shows all of the calls made by the selected member.
The call hierarchy is shown as a dockable window within the Visual Studio integrated development environment (IDE). You can see an example of the window pictured below. The incoming and outgoing calls are shown as branches of a tree, the root of which is the originally selected member. Further details of a specific call site are shown to the right when an appropriate tree node is selected. Note that each member node is expandable, allowing the incoming and outgoing calls for those elements to be browsed also.
Navigating the Call Hierarchy
To display the Call Hierarchy window for an item you can right-click the member and choose "View Call Hierarchy" from the context-sensitive menu. Keyboard users may prefer to locate the text cursor, or caret, within the symbol and press Ctrl-K, Ctrl-T. If this is the first time that you have viewed the Call Hierarchy, the selected item will be shown as the only root in the new window's tree structure.
You can expand and collapse the member's node in the tree as desired to show or hide its child nodes. At least two child nodes should be visible, one showing all of the calls to the selected member and one showing all the calls that the member makes. Each of these calls can be expanded to show its incoming and outgoing calls, allowing browsing of the complete hierarchy of calls in your project.
If you select a member in the tree, the details of the call sites for that member are displayed to the side in a separate area. This area shows more information about the member, including its location in the source code. You can double-click a call site to show the code in an editor window.
Two special cases change the nodes beneath a root node. If a member of an interface is shown, an extra "Implements" child node is present. This shows all of the matching members of classes that implement the interface. Similarly, for virtual or abstract members an "Overrides" node may be displayed, containing all matching calls in inheritance relationships. These are particularly useful where looking up a method may otherwise just show an interface or abstract element.
Call Hierarchy Options
Several additional useful options are available from the Call Hierarchy window. If you right-click a member anywhere in the tree structure, selecting "Add As New Root" promotes that member to be a root node. This does not remove the previous root node, so allows several roots to be visible simultaneously. If you wish to remove a root, select it and click the toolbar button that shows an "X" icon. You can also press the Delete key.
Finally, you can right-click a member and select "Find All References" from the context-sensitive menu that appears. This provides the same functionality as the Find All References command provided by the IDE but without first needing to select a member in a code editor window.
5 May 2010