Do not prefix enum values with type name

TypeName

DoNotPrefixEnumValuesWithTypeName

CheckId

CA1712

Category

Microsoft.Naming

Breaking Change

Breaking

Cause

An enumeration contains a member whose name begins with the type name of the enumeration.

Rule Description

Names 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 it takes to learn a new software library, and increases customer confidence that the library was developed by someone with expertise in developing managed code.

How to Fix Violations

To fix a violation of this rule, remove the type name prefix from the enumeration member.

When to Exclude Warnings

Do not exclude a warning from this rule.

Example

The following example shows an incorrectly named enumeration followed by the corrected version.

Imports System

Namespace NamingLibrary

   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
using System;

namespace NamingLibrary
{
   public enum DigitalImageMode
   {
      DigitalImageModeBitmap = 0,
      DigitalImageModeGrayscale = 1,
      DigitalImageModeIndexed = 2,
      DigitalImageModeRGB = 3
   }

   public enum DigitalImageMode2
   {
      Bitmap = 0,
      Grayscale = 1,
      Indexed = 2,
      RGB = 3
   }
}
using namespace System;

namespace NamingLibrary
{
   public enum class DigitalImageMode
   {
      DigitalImageModeBitmap = 0,
      DigitalImageModeGrayscale = 1,
      DigitalImageModeIndexed = 2,
      DigitalImageModeRGB = 3
   };

   public enum class DigitalImageMode2
   {
      Bitmap = 0,
      Grayscale = 1,
      Indexed = 2,
      RGB = 3
   };
}

Identifiers should not have incorrect suffix

Mark enums with FlagsAttribute

Do not mark enums with FlagsAttribute

See Also

Reference

System.Enum