Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Visual Studio display reference shortcut links for fields?

The Visual Studio IDE will display a shortcut link to view all usages of a class member if that member is a property. However, it does not display them if that member is a field. See screenshot below. Why is this the case? Is there an IDE setting I need to enable to get them to appear for fields?

I'm using Visual Studio 2022 17.9.2 64-bit

enter image description here

like image 560
user3163495 Avatar asked Mar 03 '26 04:03

user3163495


1 Answers

I am able to reproduce your situation:

enter image description here

Is there an IDE setting I need to enable to get them to appear for fields?

There is no way to achieve this currently.

The feature you are using is CodeLens.

It actually works for properties but not fields. Starting from VS2013, the VS never support the 'Codelens to view fields references feature' you mentioned.

Take a look of the official reply:

feature request of Visual Studio CodeLens on fields

Due to the underlying architecture of VS, the situation you mentioned cannot actually be displayed currently. You can understand that it is by design. The real CodeLens to view the fields reference does not exist and can only be used through properties.

like image 71
Bowman Zhu Avatar answered Mar 05 '26 00:03

Bowman Zhu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!