Skip to content

Gendarme.Rules.Performance.AvoidUncalledPrivateCodeRule(git)

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

AvoidUncalledPrivateCodeRule

Assembly: Gendarme.Rules.Performance
Version: git

Description

This rule will check for internally visible methods which are never called. The rule will warn you if a private method isn't called in its declaring type or if an internal method doesn't have any callers in the assembly or isn't invoked by the runtime or a delegate.

Examples

Bad example:

public class MyClass {
    private void MakeSuff ()
    {
        // ...
    }
    public void Method ()
    {
        Console.WriteLine ("Foo");
    }
}

Good example (removing unused code):

public class MyClass {
    public void Method ()
    {
        Console.WriteLine ("Foo");
    }
}

Good example (use the code):

public class MyClass {
    private void MakeSuff ()
    {
        // ...
    }
    public void Method ()
    {
        Console.WriteLine ("Foo");
        MakeSuff ();
    }
}

Source code

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

Clone this wiki locally