Skip to content

Gendarme.Rules.Performance.AvoidUnusedPrivateFieldsRule(git)

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

AvoidUnusedPrivateFieldsRule

Assembly: Gendarme.Rules.Performance
Version: git

Description

This rule checks all private fields inside each type to see if some of them are not being used. This could be a leftover from debugging or testing code or a more serious typo where a wrong field is being used. In any case this makes the type bigger than it needs to be which can affect performance when a large number of instances exist.

Examples

Bad example:

public class Bad {
    int level;
    bool b;
    public void Indent ()
    {
        level++;
        #if DEBUG
        if (b) Console.WriteLine (level);
        #endif
    }
}

Good example:

public class Good {
    int level;
    #if DEBUG
    bool b;
    #endif
    public void Indent ()
    {
        level++;
        #if DEBUG
        if (b) Console.WriteLine (level);
        #endif
    }
}

Source code

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

Clone this wiki locally