38

Does anyone know if it is possible to have resharper force the use of the this keyword when it can be used? For fields and such...

Resharper is capable of showing where it can be removed, but our coding standard tells us to use the this keyword.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Sorskoot
  • 10,190
  • 6
  • 55
  • 98
  • 1
    I'd argue that `this` is redundant (with constructors as a possible exception) because you shouldn't give method arguments or local variables the same names as fields. – kͩeͣmͮpͥ ͩ Nov 03 '10 at 13:21
  • 2
    I'm not talking about the same names... private fields start with an _, parameters don't (in our guidlines). It is much easier to spot distinct methods, properties and fields from local variables and parameters, even with differences in casing... – Sorskoot Nov 03 '10 at 14:34

2 Answers2

67

In ReSharper Options, under Code Editing -> C# -> Code Style there is an option for Use "this." qualifier for that you can set for fields, properties, events, and methods.

bdukes
  • 152,002
  • 23
  • 148
  • 175
4

Checkout the StyleCop for Resharper plugin (part of the StyleCop project).

You can then set the "default" severity for StyleCop to Error (or just this particular rule) and it will appear in the R# "files with errors" area inside Visual Studio.

Brett Veenstra
  • 47,674
  • 18
  • 70
  • 86