0

I have a class that has about 1200 constant fields. I know that some of them (maybe 10%) are deprecated/legacy fields that have 0 references in the solution. Instead of going one by one and find all references, I thought that CodeLens would show me the number of references on top of each field. Unfortunately, it turned out that CodeLens doesn't provide info for fields, only methods, classes, and properties. Is there a way to find out the "useless" fields in the class? If not, is there a way to enable CodeLens (or a similiar extension) for fields?

yazanpro
  • 4,512
  • 6
  • 44
  • 66

2 Answers2

2

As Arturo commented, code lens works fine for properties, it doesn't work for public fields.

What I would do in your case is try commenting out say 10 or 15 at a time, and then trying to compile. The error messages will show you which are needed, and you can uncomment those. This will leave the unneeded ones commented out. They can then be deleted.

The other way to do it is to copy the lines of code into a text editor and use a macro to turn each field into a property. Then paste these lines back in, and code lens will work.

Both ways will work, depends which you prefer. I'd prefer the latter, but it's largely personal.

Avrohom Yisroel
  • 8,555
  • 8
  • 50
  • 106
1

Visual Studio has a great code analysis tool built into the IDE. Here is a great article to help you find and eliminate "dead code" (unused properties, fields, etc) using code analysis.

Icemanind
  • 47,519
  • 50
  • 171
  • 296