1 year ago

#326324

test-img

Christoph

Define naming style as camelCase OR PascalCase

Is it possible to define a naming style (in VS options or .editorconfig) as either camelCase or PascalCase (the programmer can write it either way, both are accepted), without disabling the whole check?

The reason behind is that I would like to distinguish between fields that are there for technical reasons and should not be used, e.g. the backing field of a lazy initialized property, which I would write in camelCase, and fields that are there to be used (and which I do not like to convert into properties for performance, ref or other reasons), which I would like to write in PascalCase.

I tried the following in .editorconfig:

# Pascal-case style
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# Camel-case style
dotnet_naming_style.camel_case_style.capitalization = camel_case

# Private fields (instance or static, constants etc.)
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private, internal

# Private fields are camelCase or PascalCase (incl. static)
dotnet_naming_rule.private_fields_should_be_camel_case.severity = error
dotnet_naming_rule.private_fields_should_be_camel_case.symbols = private_fields
dotnet_naming_rule.private_fields_should_be_camel_case.style = camel_case_style
dotnet_naming_rule.private_fields_should_be_pascal_case.severity = error
dotnet_naming_rule.private_fields_should_be_pascal_case.symbols = private_fields
dotnet_naming_rule.private_fields_should_be_pascal_case.style = pascal_case_style

and this:

# Pascal-case style
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# Camel-case style
dotnet_naming_style.camel_case_style.capitalization = camel_case

# Private fields (instance or static, constants etc.)
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private, internal

# Private fields are camelCase or PascalCase (incl. static)
dotnet_naming_rule.private_fields_should_be_any_case.severity = error
dotnet_naming_rule.private_fields_should_be_any_case.symbols = private_fields
dotnet_naming_rule.private_fields_should_be_any_case.style = camel_case_style, pascal_case_style

c#

visual-studio

editorconfig

0 Answers

Your Answer

Accepted video resources