Export (0) Print
Expand All
Expand Minimize
2 out of 3 rated this helpful - Rate this topic

Static holder types should be sealed

TypeName

StaticHolderTypesShouldBeSealed

CheckId

CA1052

Category

Microsoft.Design

Breaking Change

Breaking

A public or protected type contains only static members and is not declared with the sealed (C# Reference) (NotInheritable) modifier.

This rule 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 sealed modifier to prohibit its use as a base type.

To fix a violation of this rule, mark the type as sealed.

Exclude a warning from this rule only if the type is designed to be inherited. The absence of the sealed modifier suggests that the type is useful as a base type.

The following example shows a type that violates the rule.

using System;

namespace DesignLibrary
{
    public class StaticMembers
    {
        static int someField;

        public static int SomeProperty
        {
            get
            {
                return someField;
            }
            set
            {
                someField = value;
            }
        }

        StaticMembers() {}

        public static void SomeMethod() {}
    }
}

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.