C#idiomatic C#
ca1711fundamentals/code-analysis/quality-rules

Code analysis

CA1711: Identifiers should not have incorrect suffix

Learn about code analysis rule CA1711: Identifiers should not have incorrect suffix

CA1711 Naming enabled by default in .NET 10: No
Fix is breaking or non-breaking BreakingApplicable languages C# and Visual Basic

Cause

An identifier has an incorrect suffix.

By default, this rule only looks at externally visible identifiers, but this is configurable.

Rule description

By convention, only the names of types that extend certain base types or that implement certain interfaces, or types derived from these types, should end with specific reserved suffixes. Other type names should not use these reserved suffixes.

The following table lists the reserved suffixes and the base types and interfaces with which they're associated.

In addition, the following suffixes should not be used:

  • Delegate
  • Enum
  • Ex or similar suffix to distinguish it from an earlier version of the same type
  • Flag or Flags for enum types
  • Impl (use Core instead)
  • New if a member with the same name but without the New suffix already exists

Naming conventions provide a common look for libraries that target the .NET common language runtime. These conventions reduce the learning curve that's required for new software libraries and increase customer confidence that the library was developed by someone with expertise in developing managed code. For more information, see Naming guidelines: Classes, Structs, and Interfaces.

How to fix violations

Remove the suffix from the type name.

Example

csharp
class BadEmployeeCollection { } // Violates CA1711

// Good
class Employee { }
class GoodEmployeeCollection : ICollection<Employee>
{
    // Implementations
}

class Employees { } // Good

When to suppress warnings

Do not suppress a warning from this rule unless the suffix has an unambiguous meaning in the application domain.

Suppress a warning

If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

csharp
#pragma warning disable CA1711
// The code that's violating the rule is on this line.
#pragma warning restore CA1711

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

ini
[*.{cs,vb}]
dotnet_diagnostic.CA1711.severity = none

For more information, see How to suppress code analysis warnings.

Configure code to analyze

Use the following options to configure which parts of your codebase to run this rule on.

You can configure these options for just this rule, for all rules they apply to, or for all rules in this category (Naming) that they apply to. For more information, see Code quality rule configuration options.

Include specific API surfaces

You can configure which parts of your codebase to run this rule on, based on their accessibility, by setting the api_surface option. For example, to specify that the rule should run only against the non-public API surface, add the following key-value pair to an .editorconfig file in your project:

ini
dotnet_code_quality.CAXXXX.api_surface = private, internal

Allow suffixes

You can configure a list of allowed suffixes, with each suffix separated by the pipe character ("|"). For example, to specify that the rule should not run against Flag and Flags suffixes, add the following key-value pair to an .editorconfig file in your project:

ini
dotnet_code_quality.ca1711.allowed_suffixes = Flag|Flags

See also