Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Visual Studio from counting references of certain methods

In Visual Studio 2013 Ultimate, Microsoft introduced a feature named CodeLens. A handy feature which (among others) has the ability to count the number of times a method is referenced in your project.

At the moment we're using VS2015 Pro and I'm working in a big solution with multiple projects in it.

The problem

Consider the following class:

public class MapItem
{
    public int Id { get; set; }
    public string Provider { get; set; }
    public string Value { get; set; }
    public bool MainItem { get; set; }
    public int? MapId { get; set; }

    public override string ToString()
    {
        return $"Provider: {Provider}, Value: {Value}, MainItem: {MainItem}";
    }
}

CodeLens would count the number of times every property is referenced and adds it above each properties' declaration. I've also overridden the ToString() method to easily read the values when printing.

Right now, every time when I open a file with a ToString() declaration or when I make changes to one, Visual Studio starts counting the references of every occasion where ToString() is used. Even when this specific method in this class is not used.

This results in Visual Studio using all my CPU (95%+) and becoming unresponsive for a few minutes.

My Question

I have already learned how to disable CodeLens reference counting completely, but this is not what I want. What I would like to know is if there is any way to tell CodeLens to stop reference counting for a single method in general, and ToString() specifically (an attribute or blacklist perhaps?). This way Visual Studio won't have to go through the hassle of counting every time an overridden method is referenced. Alternatively, I would like to see the amount of references to MapItem.ToString() only.

like image 631
Baksteen Avatar asked Apr 09 '18 09:04

Baksteen


1 Answers

It looks like, it's impossible. You can't disable reference counting for a method, and you can't disable reference counting at all. This option is disabled:

enter image description here

I have found this feature request. And Visual Studio Team won't do this.

like image 177
Backs Avatar answered Oct 07 '22 04:10

Backs