Identifiers No Incorrect Suffix
ID |
csharp.identifiers_no_incorrect_suffix |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
CSharp |
Tags |
naming |
Description
Reports C# type declarations whose name ends with a type-revealing suffix that
the .NET design guidelines discourage. By default the rule rejects the
suffixes Enum, Class, Collection, Flags and Delegate. These
suffixes encode the kind of the type in the name itself and add no value for
the callers reading the code.
The list is configurable via the suffixes property; if a project wants to
flag misuse of Exception or Attribute suffixes (which are mandated by the
framework only on genuine subclasses), it can add those names to the list. The
rule automatically skips types whose direct base type ends with the same
suffix, so legitimate *Exception and *Attribute types pass.
Three of the default suffixes mirror Roslyn’s CA1711 (Identifiers should not have incorrect suffix), whose contract is directional rather than a blanket ban: the suffix is permitted, and only a type that is not genuinely that kind is flagged for using it.
-
Enumis permitted on a type that genuinely is anenum. -
Delegateis permitted on a genuinedelegatetype. -
Collectionis permitted on a type that implementsIEnumerable— directly, through a same-file interface, or by inheriting a well-known BCL collection base type (List<T>,Dictionary<K,V>, …).
Class has no CA1711 entry at all; its inclusion in the default list is a
DepsDoctor house-style addition, not upstream parity, and is unaffected by the
exemptions above.
Rationale
Type-revealing suffixes are noise when the name doesn’t earn them.
OrderClass is just Order; naming a plain class ColorEnum when it isn’t an
enum is actively misleading. But a genuine enum named ColorEnum, a
genuine delegate named OnClickDelegate, or a genuine collection type named
ItemCollection are exactly the shapes CA1711 exists to leave alone — the
suffix documents a real fact about the type.
public class Order { } // OK
public class OrderClass { } // FLAW — Class suffix
public enum Color { } // OK
public enum ColorEnum { } // OK — genuinely an enum
public class TestDocWithEnum { } // FLAW — Enum suffix on a plain class
public class OrderCollection { } // FLAW — Collection suffix, implements nothing enumerable
public class ItemCollection : IEnumerable<T> // OK — genuinely implements IEnumerable
{
public IEnumerator<T> GetEnumerator() => ...;
}
public delegate void OnClickDelegate(); // OK — genuinely a delegate
public class Permissions { } // OK
public class PermissionsFlags { } // FLAW — Flags suffix