CA1000: Do not declare static members on generic types

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see CA1000: Do not declare static members on generic types on docs.microsoft.com.

TypeNameDoNotDeclareStaticMembersOnGenericTypes
CheckIdCA1000
CategoryMicrosoft.Design
Breaking ChangeBreaking

An externally visible generic type contains a static (Shared in Visual Basic) member.

When a static member of a generic type is called, the type argument must be specified for the type. When a generic instance member that does not support inference is called, the type argument must be specified for the member. The syntax for specifying the type argument in these two cases is different and easily confused, as the following calls demonstrate:

// Static method in a generic type.  
GenericType<int>.StaticMethod();  
  
// Generic instance method that does not support inference.  
someObject.GenericMethod<int>();  

Generally, both of the prior declarations should be avoided so that the type argument does not have to be specified when the member is called. This results in a syntax for calling members in generics that is no different from the syntax for non-generics. For more information, see CA1004: Generic methods should provide type parameter.

To fix a violation of this rule, remove the static member or change it to an instance member.

Do not suppress a warning from this rule. Providing generics in a syntax that is easy to understand and use reduces the time that is required to learn and increases the adoption rate of new libraries.

CA1005: Avoid excessive parameters on generic types

CA1010: Collections should implement generic interface

CA1002: Do not expose generic lists

CA1006: Do not nest generic types in member signatures

CA1004: Generic methods should provide type parameter

CA1003: Use generic event handler instances

CA1007: Use generics where appropriate

Generics

Show: