Vadim's Weblog

Never stop learning.

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. 

RS_privateFields

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.

RS_NamingStyle_Dialog

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:

RS_privateFields_Fixed 

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.

RS_ExstendedNamingRule

kick it on DotNetKicks.com

About these ads

2 Responses to “ReSharper 4.5 complains about my private fields.”

  1. This is good to know. Even if the preferred format is a bit blurred depending on who you ask.

    – Lee

  2. Anonymous said

    My Dad used to to add m_ or in _ in the olden days. Nowadays it really just clutters up the code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: