Reputation: 2403
I want to use m_ for non-const private members and c_ for const ones. However, editorconfig doesn't allow me to specify a rule for non-const members only as far as I can see. The following doesn't work, regardless of the order of specification of private members in general or const ones:
# Prefix private/protected fields with m_
dotnet_naming_rule.prefix_private_members.symbols = private_fields
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private;protected;protected_internal
dotnet_naming_rule.prefix_private_members.style = private_prefix_style
dotnet_naming_style.private_prefix_style.capitalization = camel_case
dotnet_naming_style.private_prefix_style.required_prefix = m_
dotnet_naming_rule.prefix_private_members.severity = warning
# Prefix private/protected const fields with c_
dotnet_naming_rule.prefix_const_members.symbols = const_fields
dotnet_naming_symbols.const_fields.applicable_kinds = field
dotnet_naming_symbols.const_fields.applicable_accessibilities = private;protected;protected_internal
dotnet_naming_symbols.const_fields.required_modifiers = const
dotnet_naming_rule.prefix_const_members.style = const_prefix_style
dotnet_naming_style.const_prefix_style.capitalization = camel_case
dotnet_naming_style.const_prefix_style.required_prefix = c_
dotnet_naming_rule.prefix_const_members.severity = warning
What do I do? I also tried using Pascal case instead of c_ to distinguish const, but the conflict still occurs since the camel_case for fields in general conflicts with that.
Upvotes: 5
Views: 2130
Reputation: 6522
I got PascalCase
for constant fields and m_camelCase
for non-constant fields.
## constant fields should be PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = error
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# private fields should be m_camelCase
dotnet_naming_rule.camel_case_for_private_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_fields.symbols = private_fields
dotnet_naming_rule.camel_case_for_private_fields.style = camel_case_underscore_style
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_style.camel_case_underscore_style.required_prefix = m_
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
Different prefixes for non-constant and constant fields seems to be an open issue (Editorconfig : Can't exclude const fields)
Upvotes: 5