views:

119

answers:

2

Is there a way to tell R# to apply different naming strategy for property backing fields (_camelCase) vs class instance fields (camelCase)?

Reason: I want my dependencies to be named just a any other variable. Especially if the type of the field is the same as the field name. For example

private readonly MetaService metaService;
+2  A: 

No, I don't know of a way to do this.

Frankly, I don't understand the distinction.

  1. A private instance field may later be used as the backing field for a property. Would you then feel it necessary to change the name of that field?
  2. The property may become disused and may then be removed. Do you then want to rename the field? It would no longer be a backing field.
John Saunders
+1 - Yep. A private field is a private field. I think a case could be made that static readonly could have different conventions (similar to const, possibly), but other than that...
TrueWill
+1  A: 

The naming convention for a property backing field should be the same as that for a class instance field. The only difference between the two is that one can be manipulated or accessed from the outside.

If you feel the need to make a distinction, add a comment.

Robert Harvey