[tweetmeme source=”aabdulmoniem” only_single=false]
Old versions of VS like 2008 was really painful when trying to navigate from an interface method to its implementation. Now, as we have seen a lot of improvements in navigability in VS 2010, we have been introduced with a very cool new window called: “Call Hierarchy”.
Only you have to right-click on any name you want to trace its call hierarchy and click on “View Call Hierarchy” like the following screen shot:

VS 2010 will handle the rest. It will open a new dockable window for you titled: “Call Hierarchy”

Lets examine some features of this window:
1 – Calls to and Calls from:
As you can see, you can investigate all the called paths from the chosen method or all the called paths to the chosen method.

2 – Call sites
You can click on any call path from the left side of the window to see all the call sites on the right window plus you can navigate to the chosen call site if you want by double clicking on any call site.

3 – Navigate to the call from or call to paths:
You can also navigate to the call path by clicking any code path from the left window.
4 – Filtering call hierarchy:
You can filter the call hierarchy by solution, project and document as shown in the following screen shot:

Now, let’s see more complex scenarios when trying to navigate for virtual or interface methods.
Suppose that we have a class Employee and Manager both are implementing an interface IHuman and inheriting from a class Person. Let’s see these four types:
Person class:
public class Person
{
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
get
{
return Title + " " + FirstName + " " + LastName;
}
}
public Person()
{
}
public Person(string title, string firstName, string lastName)
{
Title = title;
FirstName = firstName;
LastName = lastName;
}
public virtual void PrintInformation()
{
Console.WriteLine(FullName);
}
}
IHuman interface:
public interface IHuman
{
void Talk(string talking);
void Eat(string food);
}
Employee class:
public class Employee : Person, IHuman
{
public string Salary { get; set; }
#region IHuman Members
public void Talk(string talking)
{
Console.WriteLine("I am saying: " + talking);
}
public void Eat(string food)
{
Console.WriteLine("I am eating: " + food);
}
#endregion
public override void PrintInformation()
{
base.PrintInformation();
Console.WriteLine(Salary);
}
}
And Manager class:
public class Manager : Person, IHuman
{
public string DepartmentName { get; set; }
#region IHuman Members
public void Talk(string talking)
{
Console.WriteLine("I am saying: " + talking);
}
public void Eat(string food)
{
Console.WriteLine("I am eating: " + food);
}
#endregion
public override void PrintInformation()
{
base.PrintInformation();
Console.WriteLine(DepartmentName);
}
}
As you can see that Employee and Manager classes override the PrintInformation method which is a Person virtual method. Also, they implement the two methods Talk and Eat of IHuman interface.
Now let’s play with the call hierarchy feature from the Person class. Right-click on the PrintInformation method in the Person class and choose the “View Call Hierarchy” menu item. See the next screen shot:

As you can see, we can navigate to all the overrides from this window very easily and forgetting about the hassle of Find or Find All References!
Let’s switch to the IHuman interface and see what is the call hierarchy of the Talk method:

Really, pretty neat!
Like this:
Like Loading...
Read Full Post »