Do not declare protected members in sealed types
| TypeName | DoNotDeclareProtectedMembersInSealedTypes |
| CheckId | CA1047 |
| Category | Microsoft.Design |
| Breaking Change | NonBreaking |
A public type is sealed (NotInheritable in Visual basic) and declares a protected member. This rule does not report violations for Finalize methods, which must follow this pattern.
The following example shows a type that violates this rule.
using System; namespace DesignLibrary { public sealed class SealedClass { protected void ProtectedMethod(){} } }
The following example shows a type that violates this rule.
The above sealed type declares a protected member, which cannot be called from outside the class that declares it.
If the method was designed to be called by other types, increase its accessibility to public, otherwise, reduce its accessibility to private.
The following example fixes the above violation by increasing the method's accessibility to public.