none
Go To Definition RRS feed

  • Question

  • We have an application that uses many interfaces. 

    So, in Visual Studio, I see a call to a particular method.  This particular code only runs in very rare circumstances, so it's not something that I can run and step into.

    However, I do want to view the code within the method that is being called.  So, I right-click on the method name and select "Go To Definition".  But, instead of going to the implementation, it does exactly what is says it's going to do and goes to the definition in the Interface.

    So, not what I was really wanting.  Is there a simple way to jump to the implementation rather than the definition?

    Thanks in advance

    Griff

    Friday, February 19, 2010 4:58 PM

Answers

  • Is the method being called through the interface?

    i.e., if it's

    ISomething something = new Something();
    something.Foo();

    then  "Go To Definition" will jump to the interface. That's how it is in VS 2005/8. VS 2010 may be different.

    To get what you want in VS 2008 I think you're stuck with using the likes of CodeRush or ReSharper!

    Kevin
    • Marked as answer by YiChun Chen Friday, February 26, 2010 2:39 AM
    Saturday, February 20, 2010 2:15 PM
  • Thank you for Kevin's kindly help.

    Hi Griff,

    Thank you for your clarification and sample code. Now I can understand the scenario that you came across better.

    Go To Definition
    command navigates you to the definition of a selected identifier. A valid identifier is a type, a method, a field, or a local variable declaration.

     IWibble lib1 = new CalledClass();
     long answer1 = lib1.Multiply(7, 8);

    Kevin is correct. From the source code, you want to call Multiply method through IWibble interface. Thus, when we apply Go To Definition option, it will navigate to the Multiply method in IWibble interface.

     CalledClass lib2 = new CalledClass();
     long answer2 = lib2.Multiply(7, 8);
    

    For this source code, you want to call Multiply method through CalledClass class. Thus, when we apply Go To Definition option, it will navigate to the Multiply method in CalledClass class.

    I can reproduce the scenario that you came across. By default, Visual Studio doesn't support that configuration. It's by design. I've also tested the source code on Visual Studio 2010. It behaves the same.

    Hope this helps! If you have any concern, please feel free to let me know.

    Best regards,
    Yichun Chen
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by YiChun Chen Friday, February 26, 2010 2:39 AM
    Wednesday, February 24, 2010 3:58 AM
  • Hi Kevin,

    Thank you for your feedback.

    I can understand Griff's and your favor on the feature that navigates to the implementing class. If it doesn't disturb both of you a lot, you can submit this suggestion on our Connect portal site:

        https://connect.microsoft.com/VisualStudio/ 

    Every feedback submitted will be evaluated carefully by our engineers. If this suggestion is reasonable and other customers have the similar concern on this feature, they will let us know their comments further through that portal. This would be helpful to improve Visual Studio products.

    Thank you for your help.

    Hope this helps! If you have any concern, please feel free to let me know.

    Best regards,
    Yichun Chen

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by YiChun Chen Friday, February 26, 2010 2:39 AM
    Thursday, February 25, 2010 2:09 AM

All replies

  • Is the method being called through the interface?

    i.e., if it's

    ISomething something = new Something();
    something.Foo();

    then  "Go To Definition" will jump to the interface. That's how it is in VS 2005/8. VS 2010 may be different.

    To get what you want in VS 2008 I think you're stuck with using the likes of CodeRush or ReSharper!

    Kevin
    • Marked as answer by YiChun Chen Friday, February 26, 2010 2:39 AM
    Saturday, February 20, 2010 2:15 PM
  • Hi Griff,

    Thank you for your post.

    I've checked "Go To Definition" on my machine. It seems that it works well even through the interface.

    Could you please help me to check whether this scenario will happen when you create a new project? This would be helpful to isolate some possible cause of this project specific.

    Could you please clarify your concern more? If you don't mind, you could post the related source code here so that we can reproduce the situation that you came across.

    Hope this helps! If you have any concern, please feel free to let me know.

    Best regards,
    Yichun Chen
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, February 22, 2010 9:44 AM
  • Hi Yichun Chen

    Imagine the following pseudo code:

        public class CalllingClass
        {
            public CalllingClass()
            {
                IWibble lib1 = new CalledClass();
                long answer1 = lib1.Multiply(7, 8);
    
                CalledClass lib2 = new CalledClass();
                long answer2 = lib2.Multiply(7, 8);
            }
        }
    
        interface IWibble
        {
            long Multiply(long a, long b);
        }
    
        public class CalledClass : IWibble
        {
    
            #region IWibble Members
    
            public long Multiply(long a, long b)
            {
                return a * b;
            }
    
            #endregion
        }
    If you go to definition of "Multiply" on the line:

    lib1.Multiply(7, 8);

    then you'll go to the one in the Interface

    If you do it on the line:

    ib2.Multiply(7, 8);

    then you'll go to the one in the class.

    In much of our code we're using factories, so our objects are all instantiated using the interface and so the definition always takes us to the interface.  And it's a complex multi-project solution...

    Thanks

    Griff
    Tuesday, February 23, 2010 9:39 AM
  • Hi Griff, that's what I thought too. It's what happens in VS 2005/8. Is Yichun using VS 2010 and does that have different behaviour?

    Kevin
    Tuesday, February 23, 2010 12:04 PM
  • Thank you for Kevin's kindly help.

    Hi Griff,

    Thank you for your clarification and sample code. Now I can understand the scenario that you came across better.

    Go To Definition
    command navigates you to the definition of a selected identifier. A valid identifier is a type, a method, a field, or a local variable declaration.

     IWibble lib1 = new CalledClass();
     long answer1 = lib1.Multiply(7, 8);

    Kevin is correct. From the source code, you want to call Multiply method through IWibble interface. Thus, when we apply Go To Definition option, it will navigate to the Multiply method in IWibble interface.

     CalledClass lib2 = new CalledClass();
     long answer2 = lib2.Multiply(7, 8);
    

    For this source code, you want to call Multiply method through CalledClass class. Thus, when we apply Go To Definition option, it will navigate to the Multiply method in CalledClass class.

    I can reproduce the scenario that you came across. By default, Visual Studio doesn't support that configuration. It's by design. I've also tested the source code on Visual Studio 2010. It behaves the same.

    Hope this helps! If you have any concern, please feel free to let me know.

    Best regards,
    Yichun Chen
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by YiChun Chen Friday, February 26, 2010 2:39 AM
    Wednesday, February 24, 2010 3:58 AM
  • Hi Yichun,

    It would be nice if VS could acquire the option to navigate to the implementing class as this is almost always what is wanted. Maybe in the next version of VS?
    Kevin
    Wednesday, February 24, 2010 6:16 PM
  • Hi Kevin,

    Thank you for your feedback.

    I can understand Griff's and your favor on the feature that navigates to the implementing class. If it doesn't disturb both of you a lot, you can submit this suggestion on our Connect portal site:

        https://connect.microsoft.com/VisualStudio/ 

    Every feedback submitted will be evaluated carefully by our engineers. If this suggestion is reasonable and other customers have the similar concern on this feature, they will let us know their comments further through that portal. This would be helpful to improve Visual Studio products.

    Thank you for your help.

    Hope this helps! If you have any concern, please feel free to let me know.

    Best regards,
    Yichun Chen

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by YiChun Chen Friday, February 26, 2010 2:39 AM
    Thursday, February 25, 2010 2:09 AM
  • Hi,

    when I had started working with Visual Studio again (after some Java years) in the year of 2006 (3,5 years ago) I also asked this same question, i.e. how do you easily jump into one of the implementations instead of just going to the interface.
    (see thread with subject "Navigate to the implementation instead of the interface definition" posted September 6th 2006,
    http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/fd7174da-e727-416f-bdf8-8b87ea16b08c
    )

    Back then in 2006, Visual Studio 2005 did not have the feature, and as far as I can tell (since this question still keep popping up in february 2010) neither VS 2008 nor VS 2010 have this feature.

    After now having been working with Java again for some 2,5 years now, I am going back to C# development and has started experimenting with Visual Studio 2010 but still can not find the feature I was already looking for many years ago, and when doing some MSDN forum searching I found this thread with this very same question still being asked about Visual Studio.

    > I can understand Griff's and your favor on the feature that navigates to the implementing class.
    > If it doesn't disturb both of you a lot, you can submit this suggestion on our Connect portal site:
    > https://connect.microsoft.com/VisualStudio/
    > Every feedback submitted will be evaluated carefully by our engineers.
    > If this suggestion is reasonable and other customers have the similar concern on this feature, they will let us know their
    > comments further through that portal. This would be helpful to improve Visual Studio products.

    Seriously, is there really any shadow of a doubt that the feature would be reasonable and that other developers would appreciate a possibility to let you navigate into the implementing class of a method (or a small popup options thingy if there are many classes) ?

    3,5 years ago I also asked for a plugin that could provide the feature, and someone suggested me to start such a project myself...
    Actually I find it very hard to understand why me or anyone else would have to create a plugin for such a basic feature of being able to provide productive and convenient navigation in the source code as any good IDE of 2010 (e.g. Eclipse) should be able to do without any plugin.

    / Tom
    Sunday, February 28, 2010 1:26 PM
  • Okay, I've raised this with Connect: ID = 542032.  

    I think this gives you the opportunity to vote on how helpful this item would be....so if you do then you know what to do.

    Griff
    Monday, March 15, 2010 5:19 PM
  • I've voted.

    Kevin
    Tuesday, March 16, 2010 2:04 PM
  • If you go to definition of "Multiply" on the line:

    lib1.Multiply(7, 8);

    then you'll go to the one in the Interface

    If you do it on the line:

    ib2.Multiply(7, 8);

    then you'll go to the one in the class.

    In much of our code we're using factories, so our objects are all instantiated using the interface and so the definition always takes us to the interface.  And it's a complex multi-project solution...

    I understand this part now, Thanks for your explanation!
    Monday, December 20, 2010 3:53 AM