71

Is there a quick way to find all of the implementations of, not references to, an interface's method/property/etc? Here's some sample code:

public class SomeClass : IBaseClass
{
  public Int32 GetInt()
  {
     return 1;
  }
}

public interface IBaseClass
{
  public Int32 GetInt();
}

public class SomeOtherClass
{
  IBaseClass _someClass;
  private TestMethod()
  {
    _someClass = new SomeClass();
    _someClass.GetInt();
  }
}

I want to quickly get to SomeClass.GetInt() while reviewing SomeOtherClass.TestMethod(). If I right click on _someClass.GetInt() and click 'Go To Definition', it takes me to the interface. If I click 'Find All References', I could potentially see a list of all uses ... not just the classes that implement the GetInt() method.

Is there a faster way to find this? Any tips from other developers? We are using D.I. for most of our dependencies, which means that tracing through deeply nested code takes forever.

dragan.stepanovic
  • 2,767
  • 7
  • 33
  • 66
Beep beep
  • 18,063
  • 12
  • 60
  • 76

6 Answers6

117

Since I don't like to use the mouse while coding, I usually

  • move the cursor over the method
  • type ctrl+k clrl+t to open the Call Hierarchy window
  • move down to Implements node.
  • type Return to go to the selected implementation

AFAIK this is the quickest way to find the implementation of a method, without ReSharper.

(By the way: you can use the same system to move from a class method implementation to the corresponding interface declaration: just select the root)

Arialdo Martini
  • 4,217
  • 3
  • 28
  • 40
24

Alt-End will do this in ReSharper, I believe.

McGarnagle
  • 96,448
  • 30
  • 213
  • 255
lance
  • 15,310
  • 17
  • 70
  • 129
  • 17
    Ouch, $349 per developer. That's what we paid for VS2008 pro. – Beep beep Aug 11 '09 at 16:53
  • 12
    You didn't ask for a sales pitch for ReSharper, and what you're earning is none of our business, but consider what kind of money you're making doing what you're doing, and then consider how quickly you'd recoup the license fee. If the numbers are right, $350 is worth it. To give you some perspective, I'll claim that, after 1 month of actually slowing myself enough to learn ReSharper's ins and outs (and, to be sure, I'm still learning some of them) while I work, the tool increases my productivity as a code author by 30% at LEAST (it's probably higher, frankly, but I don't want to exaggerate). – lance Aug 11 '09 at 17:03
  • 5
    I agree, any company that balks at resharpers price (the C# only edition is even cheaper) is an idiot since the time you waste without costs a company $1000s. I also agree with lance's view that the cost of resharper is easily recouped in a month. – Chris Marisic Aug 11 '09 at 17:24
  • 3
    I've used it some in the past. While I found it useful for refactoring (which I don't do often), I didn't find it making me much more productive. I'll admit that I didn't spend a lot of time learning the "ins and out", but it's hard for me to justify the expense when our only problem with VS.NET is finding implemented interfaces. – Beep beep Aug 11 '09 at 17:45
  • 4
    Agreed! I don't care how much money you're making -- you'd have to use the "Go To Implementation" feature quite a lot to recoup the license fee from that feature alone! :) – lance Aug 11 '09 at 17:48
  • Also, Ctrl-Alt click will now take you to implementation: http://stackoverflow.com/a/21461161/116895 – lance Jun 02 '14 at 21:51
9

Without ReSharper the best way to do this is:

Find in files (Ctrl+Shift+F) Find What: "class*ISomeClass" Find Options: "Use Wildcards"

This will find all implementation and than you can search for your function in a concrete implementation.

Zhenya
  • 181
  • 1
  • 7
3

you could try going with this plugin:

http://blog.rthand.com/post/2010/01/18/Meet-e2809cGo-To-Implementatore2809d-DXCore-plugin-for-Visual-Studio.aspx

Robert Ivanc
  • 1,337
  • 15
  • 32
2

If your interface is in the same library as your concrete model that you'll typically want to navigate to, you could add a 'using alias' to the concrete object. 'Usings' are helpers anyhow, and this helps.

using System;
using PrimaryImplementation = YourNamespace.YourConcreteObject;


public interface IYourInterface{

}

When you're taken to the interface, you have a quick (and dirty) way of getting to the primary implementation of your interface. F12->F12!

BlackjacketMack
  • 5,052
  • 25
  • 30
1

R# has a Go to Implementation option on the pop-up menu, which is really handy for that.

Brian Rasmussen
  • 109,816
  • 33
  • 208
  • 305
  • Sounds great, nothing in VS that you know of? – Beep beep Aug 11 '09 at 16:55
  • Not beyond Find References which you already mention. If you don't know R# I really encourage you to check it out. In addition to features like this it has useful coding tip and a really powerful set of refactoring features. – Brian Rasmussen Aug 11 '09 at 17:43
  • Isn't R# a completely different programming language, or there an R# IDE as well? We are building an ASP.NET MVC app ... – Beep beep Aug 11 '09 at 18:37
  • R# is Resharper. A plug-in for Visual Studio. It adds a bunch of useful commands. – Brian Rasmussen Aug 11 '09 at 20:05
  • Ah! I had just googled R# and came up with this ( http://sourceforge.net/projects/r-sharp/ ). I'm obviously not down with lingo =) – Beep beep Aug 11 '09 at 20:54