KyleMit
KyleMit

Reputation: 30397

Custom Naming Style Options in Resharper For Backing Fields

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?

Upvotes: 2

Views: 712

Answers (1)

rpeshkov
rpeshkov

Reputation: 5057

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.

Upvotes: 3

Related Questions