2

The coding standard in my organization is for private fields to be lowerCamelCase but backing fields used by properties to be prefixed with an underscore (_). Is there a way to add a rule just for backing fields in the Resharper Naming Style tool.

Here's the Naming Rule Editor: resharper

I'd rather this error not show up for local variables rename

Examples in VB and C#:

VB:

Public Class Employee

    'Should be lowerCamelCase
    Private useCode As String = "NEW"

    'should be _lowerCamelCase
    Private _name As String

    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property

End Class

C#:

public class Employee
{

    //Should be lowerCamelCase
    private string useCode = "NEW";

    //should be _lowerCamelCase
    private string _name;

    public string Name {
        get { return _name; }
        set { _name = value; }
    }

}

Whether you agree or not with this naming convention, is there a way to ask reshaper to enforce this?

Community
  • 1
  • 1
KyleMit
  • 30,350
  • 66
  • 462
  • 664

1 Answers1

3

There is no way to enforce naming rules for backing fields in ReSharper, but you can add multiple rules for entity kind.

enter image description here

With this settings applied, ReSharper will allow you to have fields with and without underscore prefix.

rpeshkov
  • 4,877
  • 3
  • 27
  • 43
  • That's perfect! I'm so anal about getting resharper suggestions down to a minimum. I like that it's enforcing both rules and it's up to me to make sure its the correct one. – KyleMit Aug 12 '13 at 19:37