none
Code Lens shows all references, including base class, not just from the child class

    Question

  • I have a base view model that contains a LoadDaat() method, which can be overridden in the child view models.

    If I use the Code Lens references link in a child view model, it shows me every reference to the base view model's method, not just references to the overridden method in this class.

    Is there a way of seeing references only to the overridden method?

    Thanks

    Monday, March 27, 2017 2:18 PM

Answers

  • Thanks for submitting that.

    In case it helps anyone, I have found a workaround, albeit a pretty poor one.

    If your class looks like this...

    public class Jim : Fred {
      public override string DoFredStuff() {
        // Do something Jim-like...
      }
    }

    ...then (as mentioned above), code lens will show links to usages of all overrides of DoFredStuff(). If you temporarily remove the ": Fred" from the class, then CodeLens will only show usages of this specific override.

    Note that this is very likely to break your build, so you have to put Fred back before you can run, but it does help you see the real references to this override.

    Hope this helps someone.

    • Marked as answer by Mr Yossu Wednesday, March 29, 2017 1:00 PM
    Wednesday, March 29, 2017 1:00 PM

All replies

  • Hi Mr Yossu,

    Thanks for posting here.

    >>>Is there a way of seeing references only to the overridden method?

    The answer is negative. The CodeLens is designed for providing the information about our project's code just before the methods/properties/class into editor, like reference counts of methods/properties and classes, tests (Unit Tests) associated with a method and how many times the line of code has been changed.

    In other words we can say that CodeLens describes the following three important things: References, Impact, Test, Changes.

    As far as I know, there is no filter option or setting for reference type about the CodeLens, so we could not see the references only to the overridden method.

    Besides, is this filter important to you? If yes, could you share your reason for us? If it is reasonable, we will help you submit a user voice to the Visual Studio team.

    Hope this can help you.


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Tuesday, March 28, 2017 9:51 AM
  • So it's useless for overridden methods? Shame, it's one of the most useful features to have been added to VS for years. Pity we can't use it in such an obvious situation.

    Thanks anyway

    Tuesday, March 28, 2017 1:12 PM
  • @Mr Yossu, I have submit a user voice to Visual Studio team, you can follow with your comments and check the feedback of this voice. I will also follow up this voice, I will send you the latest status of this voice.

    https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/18760366-add-a-filtering-function-for-code-lens

    If above answer resolved you question, you can Mark it as Answer, if not, please let us to know the latest information about this question. Thanks.


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, March 29, 2017 8:46 AM
  • Thanks for submitting that.

    In case it helps anyone, I have found a workaround, albeit a pretty poor one.

    If your class looks like this...

    public class Jim : Fred {
      public override string DoFredStuff() {
        // Do something Jim-like...
      }
    }

    ...then (as mentioned above), code lens will show links to usages of all overrides of DoFredStuff(). If you temporarily remove the ": Fred" from the class, then CodeLens will only show usages of this specific override.

    Note that this is very likely to break your build, so you have to put Fred back before you can run, but it does help you see the real references to this override.

    Hope this helps someone.

    • Marked as answer by Mr Yossu Wednesday, March 29, 2017 1:00 PM
    Wednesday, March 29, 2017 1:00 PM