Skip to content

Gendarme.Rules.Design.DoNotDeclareProtectedMembersInSealedTypeRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

DoNotDeclareProtectedMembersInSealedTypeRule

Assembly: Gendarme.Rules.Design
Version: git

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

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally