Visual Studio 2012: Did You Call Me?

Posted Mon, Sep 3 2012 18:42 by Deborah Kurata

As you debug and refactor your application, you often want to know who called whom. Visual Studio has always provided features to help you with that, but Visual Studio 2012 provides more.

With the following, you can determine which properties and methods called which properties and methods:

  • Solution Explorer features (new in VS 2012)
  • Call Stack
  • Call Hierarchy (new in VS 2010 for C#; VS 2012 for VB)
  • Find all References

Solution Explorer

The new Solution Explorer in Visual Studio 2012 allows you to drill down from a code file to the classes, properties, and methods within that code file. From a property or method, you can view all of the properties or methods it calls. Or you can view all of the properties and methods that call it. Or you can view each line of code that uses it.

In Solution Explorer, drill down from a project to a class to a property or method. Right-click on the property or method to view the context menu.

image

Select the Calls option to see all of the properties and methods that the selected property or method calls. For example, the FindCustomers method calls the following properties and methods:

image

Select Is Called By to see all of the properties and methods that call the selected property or method. For example, the FindCustomers method is called by the following methods:

image

Select Is Used By to see each line of code that uses the the selected property or method. For example, the FindCustomers method is called by the following lines of code.

image

In all of these scenarios, you can click on a result to view it in the Preview Tab or double-click on a result to view it in a normal tab.

Call Stack

The Call Stack (Debug | Windows  | )  is only available when debugging. From it, you can see all of the calls that led to the break point. Double-click on an entry in the Call Stack to jump to that location in the code.

image

Call Hierarchy

The Call Hierarchy (View | Call Hierarchy) is only available when debugging. Right-click on a property or method name in the code window when on a break point and select View Call Hierarchy.

image

The left pane displays the "calls  to" and the "calls from" the selected property or method. Clicking on one of the properties or methods displays the associated line(s) of code.

Find All References

This one has been around for a while, so I probably don't need to provide any instructions. Just right-click on any property or method in a code file and select Find All References from the context menu.

Use these techniques any time you need to navigate the call stack.

Enjoy!

Filed under: , , ,

Comments

# Interesting Finds: September 4, 2012

Tuesday, September 04, 2012 4:02 AM by Jason Haley

Interesting Finds: September 4, 2012

# Solution Explorer in Visual Studio 2012

Sunday, September 09, 2012 5:53 PM by Deborah's Developer MindScape

There are lots of new Solution Explorer features in Visual Studio 2012, so many that they did not all

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: