Identifiers should have correct suffix
Identifiers should have correct suffix
Microsoft docsDescription
By convention, the names of types that extend certain base types or that implement certain interfaces, or types derived from these types, have a suffix that is associated with the base type or interface.
Naming conventions provide a common look for libraries that target the common language runtime. This reduces the learning curve that is required for new software libraries, and increases customer confidence that the library was developed by someone who has expertise in developing managed code.
The following table lists the base types and interfaces that have associated suffixes.
| Base type/Interface | Suffix | |------------------------------------------------------------------------------------|-----------------------------| | System.Attribute | Attribute | | System.EventArgs | EventArgs | | System.Exception | Exception | | System.Collections.ICollection | Collection | | System.Collections.IDictionary | Dictionary | | System.Collections.IEnumerable | Collection | | System.Collections.Generic.IReadOnlyDictionary2 | Dictionary | | System.Collections.Queue | Collection or Queue | | System.Collections.Stack | Collection or Stack | | System.Collections.Generic.ICollection1 | Collection | | System.Collections.Generic.IDictionary2 | Dictionary | | System.Data.DataSet | DataSet | | System.Data.DataTable | Collection or DataTable | | System.IO.Stream | Stream | | System.Security.IPermission | Permission | | System.Security.Policy.IMembershipCondition | Condition | | An event-handler delegate. | EventHandler` |
Types that implement System.Collections.ICollection and are a generalized type of data structure, such as a dictionary, stack, or queue, are allowed names that provide meaningful information about the intended usage of the type.
Types that implement System.Collections.ICollection and are a collection of specific items have names that end with the word Collection. For example, a collection of System.Collections.Queue objects would have the name QueueCollection. The Collection suffix signifies that the members of the collection can be enumerated by using the foreach (For Each in Visual Basic) statement.
Types that implement System.Collections.IDictionary or System.Collections.Generic.IReadOnlyDictionary2 have names that end with the word Dictionary even if the type also implements System.Collections.IEnumerable or System.Collections.ICollection. The Collection and Dictionary` suffix naming conventions enable users to distinguish between the following two enumeration patterns.
Types with the Collection suffix follow this enumeration pattern.
Types with the Dictionary suffix follow this enumeration pattern.
A System.Data.DataSet object consists of a collection of System.Data.DataTable objects, which consist of collections of System.Data.DataColumn and System.Data.DataRow objects, among others. These collections implement System.Collections.ICollection through the base System.Data.InternalDataCollectionBase class.
Cause
An identifier does not have the correct suffix.
By default, this rule only looks at externally visible identifiers, but this is configurable.
How to fix violations
Rename the type so that it is suffixed with the correct term.
Example
foreach(SomeType x in SomeCollection) { }When to suppress
It is safe to suppress a warning to use the Collection suffix if the type is a generalized data structure that might be extended or that will hold an arbitrary set of diverse items. In this case, a name that provides meaningful information about the implementation, performance, or other characteristics of the data structure might make sense (for example, BinaryTree). In cases where the type represents a collection of a specific type (for example, StringCollection), do not suppress a warning from this rule because the suffix indicates that the type can be enumerated by using a foreach statement.
For other suffixes, do not suppress a warning from this rule. The suffix allows the intended usage to be evident from the type name.