Static holder types should be Static or NotInheritable
Static holder types should be Static or NotInheritable
Microsoft docsDescription
Rule CA1052 assumes that a type that contains only static members is not designed to be inherited, because the type does not provide any functionality that can be overridden in a derived type. A type that is not meant to be inherited should be marked with the static modifier in C# to prohibit its use as a base type. Additionally, its default constructor should be removed. In Visual Basic, the class should be converted to a module.
This rule does not fire for abstract classes or classes that have a base class. However, the rule does fire for classes that support an empty interface. In the latest analyzer implementation of this rule, it also encompasses the functionality of rule CA1053.
Cause
A non-abstract type contains only static members (other than a possible default constructor) and is not declared with the static or Shared modifier.
By default, this rule only looks at externally visible types, but this is configurable.
How to fix violations
To fix a violation of this rule, mark the type as static and remove the default constructor (C#), or convert it to a module (Visual Basic).
Example
#pragma warning disable CA1052
// The code that's violating the rule is on this line.
#pragma warning restore CA1052When to suppress
You can suppress violations in the following cases:
- The type is designed to be inherited. The absence of the
staticmodifier suggests that the type is useful as a base type. - The type is used as a type argument. Static types can't be used as type arguments.