Using the Call Hierarchy (C# Only)
Keyboard: CTRL + ALT + K (anywhere); CTRL + K,T (cursor must be on a member name)
Menu: View -> Call Hierarchy
Command: View.CallHierarchy; EditorContextMenus.CodeWindow.ViewCallHierarchy
Versions: 2010
Published: 1/19/2010
Code: vstipTool0005
For the C# folks this is one heck of a great feature: The Call Hierarchy. It allows you to visualize all calls to and from a selected method, property, or constructor. To see how it works just right-click on any method, property, or constructor in the Editor and select View Call Hierarchy:
You should get a window similar to this one (amount of information will vary):
Notice there are "Calls To" and "Calls From" areas related to your selection. You can expand them out:
When you click on a node in the tree, the Call Sites window updates so you can visit the call if you want to:
You can continue expanding the hierarchy to see more "Calls To" and "Calls From" information:
The best part is you can right-click on a symbol and get all kinds of options:
Here are some options you may come across:
Context Menu Item |
Description |
---|---|
Add As New Root |
Adds the selected node to the tree view pane as a new root node. |
Remove Root |
Removes the selected root node from the tree view pane. This option is available only from a root node. You can also use the Remove Root toolbar button to remove the selected root node. |
Go To Definition |
Runs the Go To Definition command on the selected node. This navigates to the original definition for a method call or variable definition. You can also press F12 to run the Go To Definition command on the selected node. |
Find All References |
Runs the Find All References command on the selected node. This finds all the lines of code in your project that reference a class or member. You can also use SHIFT+F12 to run the Find All References command on the selected node. |
Copy |
Copies the contents of the selected node (but not its subnodes). |
Refresh |
Collapses the selected node so that re-expanding it displays current information. |
Comments
Anonymous
January 18, 2010
This is an excellent new feature that I'm looking forward to in VS2010. Thanks!Anonymous
January 19, 2010
Why would this feature be C# only ? I thought you guys had decided to bring VB.Net and C# on par, shouldn't this include editor features ?Anonymous
January 19, 2010
Jens, We are but anytime you have two different teams working on stuff you will naturally get some features in one language that isn't in another. VB, for example, can do embedded XML in the code whereas C# can't. ZAnonymous
March 30, 2010
Why show calls to .net assemblies? I cannot find my own code from all the calls to .net assemblies (like string.Substr....Anonymous
March 31, 2010
Ziv, You will be happy to know I passed this along to Sean and he passed it to DJ (who is responsible for this feature) and they liked it! So it is on the list of to do's for our next version of VS. I can't guarantee it will make the cut but it is definitely on the list now. ZAnonymous
May 14, 2010
Surely the most obvious use-case for a "Call Hierarchy" feature is to see the call hierarchy within MY code? Why is there no feature to remove all the calls to things like List<>.Add() or object.Equals() which are completely uninteresting and immensely clutter up the list?Anonymous
May 14, 2010
Timwi, Yeah, I've gotten that feedback and have pinged the team. I think they are planning to implement that option but not sure which release. ZAnonymous
September 17, 2010
Hi Zain, Can I use the Call Hierarchy feature in an add-in programmatically? I want the add-in to get the lists 'calls from' and 'calls to' and then manipulate it. Is that possible?Anonymous
September 22, 2010
Mazin, I talked with my friend Dustin Campbell and he pointed me to this msdn.microsoft.com/.../ee431043.aspx Based on what I see that is avaiable I'm going with "yes".Anonymous
May 16, 2011
It would be great if one could print a call hierarchy of a class library to a text file. This could be used for documentation, understanding better how a library works, new programmers joining a project team, etc. I personally am responsible for several large projects and have no way of passing the mentioned information conveniently to personal who have a need to know. I am toying with the idea of writing an addon to do just that. Sometthing like the old cross reference print outs use in the old IBM days back in the 70's. Would appreciate your feed back. Terry NorenAnonymous
May 16, 2011
Hey Terry, I like it when anyone cranks a new extension to VS :) Before you do, however, in VS 2010 Ultimate you can generate dependency graphs and UML diagrams that may fill the bill. Have you looked at some of those? ZAnonymous
May 17, 2011
I am using 2010 professional cannot find anything useful there.Anonymous
May 17, 2011
Onetjn, The UML Diagrams and dependency graphs are limited to Ultimate. Z