countunique
countunique

Reputation: 4296

Visual Studio: How to find all calls to function

There are two calls to the function B:Bla below, but looking at the call hierarchy (Cntl-K Cntl-T) and then 'Calls to' for each of A:Bla and B:Bla yields that one call is going to A and one call is going to B.

I'm working on a very large code base and sometimes I want the all calls to a function and I don't want to click 'Calls to' for each function in the inheritance chain. So for the below example, I would like 'Calls to' to return both calls, regardless of whether I called it on A:Bla or B:Bla.

using System;

class A
{
    public virtual int Bla() {
        return 65;
    }
}

class B : A
{
    public override int Bla()
    {
        return 66;
    }

    int Helper()
    {
        return this.Bla();
    }

    static void Main()
    {
        A obj = new B();
        Console.WriteLine(obj.Bla());
        Console.Read();
    }
}

Upvotes: 17

Views: 62159

Answers (5)

live-love
live-love

Reputation: 52366

From the Visual Studio menu, select View - Call Hierarchy (Ctrl + Alt + K).

To find out from where the function is being called, look at the Call Sites section.

enter image description here

Upvotes: 0

PCS-I
PCS-I

Reputation: 423

Here are the basic shortcuts for function references :

  • Find all references: Shift + Alt + F12
  • Peek references: Shift + F12

Using Windows version 1.31.1

Upvotes: 3

Wes
Wes

Reputation: 866

In case someone finds their way here looking for a way to do it with VS Code:

  • Highlight a method and use shift+F12, or
  • Right click on a method and choose Find All References

Upvotes: 2

ThomasMcLeod
ThomasMcLeod

Reputation: 7769

In Visual Studio 2015, try View | Call Hierarchy, or Ctrl + Alt + K on standard keyboard mapping. This brings up a tree with "call to " and "Calls from " subtrees.

Unfortunately, unlike Eclipse CDT, this call graph does not appear to be indexed.

Upvotes: 5

OCDan
OCDan

Reputation: 1153

You can use the 'Find All References' function, highlight the method in question and press Ctrl + F12, or right click and pick Find All References.

This will then show the results in the Find Symbol Results window.

Please see this link for more details information. http://www.blackwasp.co.uk/VSFindAllReferences.aspx

Upvotes: 13

Related Questions