Skip to content

Gendarme.Rules.Design.DoNotDeclareProtectedMembersInSealedTypeRule(2.10)

Sebastien Pouliot edited this page Jan 22, 2011 · 2 revisions

DoNotDeclareProtectedMembersInSealedTypeRule

Assembly: Gendarme.Rules.Design
Version: 2.10

Description

This rule ensures that sealed types (i.e. types that you can't inherit from) do not define family (protected in C#) fields or methods. Instead make the member private so that its accessibility is not misleading.

Examples

Bad example (field):

public sealed class MyClass {
    protected int someValue;
}

Bad example (method):

public sealed class MyClass {
    protected int GetAnswer ()
    {
        return 42;
    }
}

Good example (field):

public sealed class MyClass {
    private int someValue;
}

Good example (method):

public sealed class MyClass {
    private int GetAnswer ()
    {
        return 42;
    }
}

Notes

  • Prior to Gendarme 2.2 this rule applied only to fields and was named DoNotDeclareProtectedFieldsInSealedClassRule
Clone this wiki locally