ReSharper 4.5 complains about my private fields.
Posted by Vadim on April 9, 2009
I just downloaded ReSharper 4.5. I probably will blog more about my experience with it.
The first thing I noticed after upgrading to R# 4.5 is that I got a lot of complains (blue underlines) about my naming of non public fields.
Like many developers I like to prefix my private variables with an underscore. I know for the fact that I’m not alone that what Jeff Prosie says:
As a matter of personal preference, I typically prefix the names of private fields with an underscore (for example, _connection). When I read the code back after a time away, this makes it obvious to me which fields are not intended for public consumption. This conventions is used quite a lot in the .NET Framework – for example, in System.NET.HttpWebRequest and System.Web.HttpContext – but it is not used throughout.
Next thing I did is to check what controls this blue lines. I went to ReSharper/Options/Naming Style.
To satisfy my naming style I click on Edit button to open an Edit “Instance fields (non public)” Rule Settings… window and typed an underscore (_) in Name Prefix text box:
After modifying “Instance fields (not public)” rule, ReSharper will not complain when we add underscore to our private, internal, and protected fields. But what if we want this rule for private fields only. Well, in this case we need to define our own rule. Naming Style window has two list boxes, the second one (User defined naming rules) allows us to define our own rule.