Skip to content

Gendarme.Rules.Design.AvoidRefAndOutParametersRule(git)

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

AvoidRefAndOutParametersRule

Assembly: Gendarme.Rules.Design
Version: git

Description

This rule fires if a method uses ref or out parameters. These are advanced features that can easily be misunderstood and misused (by the consumer). This can result in an API that is difficult to use so avoid them whenever possible. An alternative is to use one of the new generic Tuple types (FX v4 and later) as the return value. No defect will be reported if the method:

Examples

Bad example:

public bool NextJob (ref int id, out string display)
{
    if (id < 0)
    return false;
    display = String.Format ("Job #{0}", id++);
    return true;
}

Good example:

private int id = 0;
private int GetNextId ()
{
    int id = this.id++;
    return id;
}
public string NextJob ()
{
    return String.Format ("Job #{0}", Id);
}

Notes

  • This rule is available since Gendarme 2.0

Source code

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

Clone this wiki locally