Skip to content

Gendarme.Rules.Design.FinalizersShouldBeProtectedRule(2.10)

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

FinalizersShouldBeProtectedRule

Assembly: Gendarme.Rules.Design
Version: 2.10

Description

This rule verifies that finalizers are only visible to the type's family (e.g. protected in C#). If they are not family then they can be called from user code which could lead to problems. Note that this restriction is enforced by the C# and VB.NET compilers but other compilers may not do so.

Examples

Bad example (IL):

.class family auto ansi beforefieldinit BadPublicFinalizer extends
[mscorlib]System.Object
{
    .method public hidebysig instance void Finalize() cil managed
    {
        // ...
    }
}

Good example (C#):

public class GoodProtectedFinalizer {
    // compiler makes it protected
    ~GoodProtectedFinalizer ()
    {
    }
}

Good example (IL):

.class family auto ansi beforefieldinit GoodProtectedFinalizer extends
[mscorlib]System.Object
{
    .method family hidebysig instance void Finalize() cil managed
    {
        // ...
    }
}
Clone this wiki locally