views:

57

answers:

2

What I'm trying to say is, if an object is defined as an interface, then instantiated from a class factory, is it possible in VS 2008 to right click on a method call from that object and see the real code, instead of the interface's empty signature?

In other words there's a lot of this in our code:

ISomeInterface myObject = ObjectCreationFactory.CreateConcreteClassX();

myObject.DoSomething();

If I right click DoSomething() and go to its definition, I wind up seeing the (blank) method definition in ISomeInterface, and not that of the class returned by the ObjectCreationFactory.

Certainly I can go to the source in CreateConcreteClassX() and see what class is being instantiated, then go from there, but it'd be nice if there were a way in VS2008 to tell it "don't look at the interface, look at the concrete implementation." Could be I'm dreaming, but thought I'd ask anyway. Thanks for the help.

+2  A: 

CreateConcreteClass() could return any object that implments ISomeInterface, so there's no way to tell at compile time which method an interface member will point to. You could always trace into the call and see where you wind up.

David Lively
+5  A: 

Try the plugin Resharper. With right click you can go directly to the implementation.

rdkleine
I think this is a little overkill if it's just about that feature. ReSharper does way more (you'll like it!). Necessary to point out that there's also a competing product called CodeRush that can do that too.
Johannes Rudolph