Search code examples
c#visual-studioresharperstylecop

Handling the this Keyword and Opening Braces with ReSharper and StyleCop


I hope that someone can help me here. I have hunted on and off over the past few weeks. It is a two part question of things that are annoying me!

I do not like the this keyword stuck in front of everything. Before I installed Stylecop I recall that ReSharper offered to remove these as redundant. With StyleCop this no longer happens. Worse when I reformat or otherwise fiddle with the code the this keyword seems to appear automagically where I did not ask for it. I have tried turning off StyleCop's inspection for this and turning on ReSharpers. RS does not offer to remove it. I have concluded that it must be something to do with code formatting but I cannot find anything.

A smaller annoyance is that I prefer my opening brace on the same line as the statement it refers to. Again it keeps getting shunted down. I wonder if this is in the same area and I am just not seeing the wood for the trees.


Solution

  • You can get resharper to ignore the this keyword by changing Resharper->Options->Languages->C#->Formatting Style->Other->Force "this." qualifier for instance member to 'Do not use'. Installing Stylecop always resets this setting to 'Use always'.

    enter image description here

    With regard to the braces, you can change them under Resharper->Options->Languages->C#->Formatting Style->Braces Layout and use the 'At and of line (K&R style)'.