在editorconfig中为const和非const私有成员使用不同的前缀

时间:2018-03-15 20:25:38

标签: c# visual-studio const editorconfig

我想将m_用于非const私有成员,将c_用于const用户。但是,只有我能看到,editorconfig不允许我为非const成员指定规则。以下不起作用,无论私人成员的规范顺序如何,还是常规成员:

# 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

我该怎么办?我也尝试使用Pascal案例而不是c_来区分const,但是冲突仍然发生,因为字段的camel_case一般与此冲突。

1 个答案:

答案 0 :(得分:0)

对于常数字段,我得到了PascalCase,对于非常数字段,我得到了m_camelCase

## 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

非恒定字段和恒定字段的不同前缀似乎是open issue (Editorconfig : Can't exclude const fields)