An enumeration contains a member whose name starts with the type name of the enumeration.
Rule descriptionNames of enumeration members are not prefixed with the type name because type information is expected to be provided by development tools.
Naming conventions provide a common look for libraries that target the common language runtime. This reduces the time that is required for to learn a new software library, and increases customer confidence that the library was developed by someone who has expertise in developing managed code.
How to fix violationsTo fix a violation of this rule, remove the type name prefix from the enumeration member.
When to suppress warningsDo not suppress a warning from this rule.
ExampleThe following example shows an incorrectly named enumeration followed by the corrected version.
public enum DigitalImageMode
{
DigitalImageModeBitmap = 0,
DigitalImageModeGrayscale = 1,
DigitalImageModeIndexed = 2,
DigitalImageModeRGB = 3
}
public enum DigitalImageMode2
{
Bitmap = 0,
Grayscale = 1,
Indexed = 2,
RGB = 3
}
Imports System
Namespace ca1712
Enum DigitalImageMode
DigitalImageModeBitmap = 0
DigitalImageModeGrayscale = 1
DigitalImageModeIndexed = 2
DigitalImageModeRGB = 3
End Enum
Enum DigitalImageMode2
Bitmap = 0
Grayscale = 1
Indexed = 2
RGB = 3
End Enum
End Namespace
Use the following option to configure which parts of your codebase to run this rule on.
You can configure this option for just this rule, for all rules it applies to, or for all rules in this category (Naming) that it applies to. For more information, see Code quality rule configuration options.
Enum values prefix triggerYou can configure the number of enumeration values required to trigger the rule. For example, to specify that the rule is triggered if one or more the enum values starts with the enum type name, add the following key-value pair to an .editorconfig file in your project:
dotnet_code_quality.CA1712.enum_values_prefix_trigger = AnyEnumValue
Examples:
Option value Summarydotnet_code_quality.CA1712.enum_values_prefix_trigger = AnyEnumValue
The rule is triggered if any of the enum values starts with the enum type name. dotnet_code_quality.CA1712.enum_values_prefix_trigger = AllEnumValues
The rule is triggered if all of the enum values start with the enum type name. dotnet_code_quality.CA1712.enum_values_prefix_trigger = Heuristic
The rule is triggered using the default heuristic, that is, when at least 75% of the enum values start with the enum type name. See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4