简体   繁体   中英

In Visual Studio, make CodeLens "References" counter/list for an Interface method implementation only count THAT implementation

In Visual Studio, we have the CodeLens reference counter above each property/method that tells how many C#/Visual Basic references there are to said member. However, if the member is inside a class, and is an implementation of a member within an Interface the class implements, then the reference counter doesn't reflect the number of references to the class's implementation -- it reflects the number of references to EVERY implementation of the Interface's member, in EVERY class. And the same goes for the list of those references.

This seems silly to me. If I want to find references to a Function or Property within my class, I want to find references to THAT Function or Property -- not other Functions and Properties like it within dozens of other classes.

This is particularly a problem for implementations of built-in Interfaces from the .NET framework, like IEnumerable . I want the references counter/list for my class's GetEnumerator method to show me where and how many times the enumerator for MY class is used -- I really don't care how many times the IEnumerable.GetEnumerator method is referenced by every class in my solution!

So, is there any way to make the References counter/list work how I want, and only reflect the usages of the current class's implementation of Interface members? I don't see any options for this under the CodeLens options but I'm hoping there may be another way...

Unfortuantely you seem to be out of luck. This has been reported in 2017 already ( https://developercommunity.visualstudio.com/content/problem/20609/code-lens-reference-count-is-broken.html ) and has been promptly reviewed 2 years (sic!) later, after the issue was moved to github ( https://github.com/dotnet/roslyn/issues/32738 )

To quote the answer:

The current CodeLens behavior is by design. However, keep in mind that we have recently done many improvements to the Find All References experience, which we anticipate will better meet the needs of users interested in finding particular kinds of references. When using Find All References, you can right click the columns and choose Show Columns → Kind to see the new reference kind designations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM