2

我想将 m_ 用于非常量私有成员,将 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 通常与此冲突,因此冲突仍然存在。

4

1 回答 1

2

我得到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

非常量和常量字段的不同前缀似乎是一个悬而未决的问题(Editorconfig:不能排除常量字段)

于 2018-10-08T14:43:59.930 回答