Identifiers should not have incorrect suffix (CA1711, Microsoft Naming)

by Mark Zhou 25. October 2010 20:53

Naming convention provides a common look for the libraries that target to the Common Language Runtime (CLR), by convention, only a few types that extend certain base types or implement base interfaces can have suffix. For example, any types that extend System.Attribute, or System.Exception should have “Attribute” or “Exception” suffix.

Oppositely, other types, or identifiers, should not have suffix if they are not listed in this article. Furthermore, the below table shows a list of reserved suffixes, which are associated with their base types or interfaces.

Suffix Base types/interfaces
Attribute System.Attribute
Collection System.Collections.ICollection
System.Collections.Generic.ICollection<T>
System.Collections.IEnumerable
System.Collections.Generic.IEnumerable<T>
System.Collections.Queue
System.Collections.Generic.Queue<T>
System.Collections.Stack
System.Collections.Generic.Stack<T>
System.Data.DataTable
System.Data.DataSet
Dictionary System.Collections.IDictionary
System.Collections.Generic.IDictionary<TKey, TValue>
EventArgs System.EventArgs
EventHandler Event handler delegates
Exception System.Exception
Permission System.Security.IPermission
Queue System.Collections.Queue
System.Collections.Quque<T>
Stack System.Collections.Stack
System.Collections.Generic.Stack<T>
Stream System.IO.Stream

In addition, the following rules also apply:

  • Do not suffix delegates with “Delegate”. suffix its type name is redundant.
  • Do not suffix enums with “Enum”, suffix its type name is redundant.
  • If member of a type implements an interface, or the member overrides an abstract member, or a type implements an external interface (that is, a COM visible interface or interface defined in other assembly), do not suffix it with “Impl” (many C++ transferred developers usually do this which is not compliant with this rule), use “Core” instead. e.g. CanCompareBitCore.
  • If you have different versions of types defined in your libraries, do not distinguish the earlier  and newer versions by adding “Ex” or similar suffix (many C++ migrated developers usually do this, which is causing a violation of this rule). Alternatively, use a sequential number such as “2”, “3” as its suffix. e.g. System.ServiceModel.Activation namespace defines WebServiceHostFactory type, then in a WCF REST extension library, a WebServiceHostFactory2 type may be defined to extend the existing features of WebServiceHostFactory; another example is the IAutoComplete2 interface of the Windows API.

Do not suppress this rule in any case.

To get more information about this rule, please see the MSDN link for CA1711 for details.

Tags: , , ,

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Translate This Page

About Mark

Mark is a developer who works for building base class libraries and tools for developers.

Mark's Awards

Microsoft Community Contributor

Month List

Who visit this site

Recent Comments

Comment RSS