Go To Implementation with View Call Hierarchy

Hands down, my favorite thing about ReSharper is that it adds Go To Implementation to the context menu for easy navigation to a function in a class that implements an interface. That’s kind of a wordy statement, so let me rephrase. Consider the example below. If I have a variable foo of type IFoo, ReSharper lets me right-click a call to foo.Bar() and jump directly to the implementation in either BasicFoo or ExtremeFoo.

interface IFoo
{
    public void Bar();
}

class BasicFoo : IFoo
{
    public void Bar()
    {
        Console.WriteLine("BasicFoo.Bar()");
    }
}

class ExtremeFoo : IFoo
{
    public void Bar()
    {
        Console.WriteLine("ExtremeFoo.Bar()");
    }
}

But what if you don’t have ReSharper? I used to think the next best option was Find All References, which does a good job of finding all the right places where you might want to look for an implementation. However, the implementations are mixed with the method itself and calls to the method, and the results returned by Find All References can become rather unruly.

find-all-references

Note that I said “used to think,” though. See that option under Find All References in the context menu, View Call Hierarchy? Use that. If you look at the Call Hierarchy for an interface method, you’ll get a group of implementations–exactly what I love about ReSharper’s Go To Implementation! You’ll also have a group of callers to the method which is what you get from another ReSharper nicety, Find Usages. Awesome.

call-hierarchy

Call Hierarchy is pretty amazing, and it’s kind of a bummer that I didn’t know about it until just now. Find All References still has its uses, but it’s taking a backseat to View Call Hierarchy in my toolkit. If you haven’t used it before, give it a shot–I bet you’ll love it, too.

Advertisement

Author: Adam Prescott

I'm enthusiastic and passionate about creating intuitive, great-looking software. I strive to find the simplest solutions to complex problems, and I embrace agile principles and test-driven development.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: