Skip to content

Gendarme.Rules.Maintainability.RemoveDependenceOnObsoleteCodeRule(git)

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

RemoveDependenceOnObsoleteCodeRule

Assembly: Gendarme.Rules.Maintainability
Version: git

Description

This rule will warn you if your code depends on (e.g. inherit, implement, call...) code that is decorated with the Obsolete attribute. Note that the rule does not report Obsolete types, methods... but only their use by your code.

Examples

Bad example:

[Obsolete ("Limited to In32.MaxValue, use new Int64 ReportAll method")]
abstract int Report (IList list);
abstract long ReportAll (IList list);
public int GetCount ()
{
    // this method is not ok since it use an obsolete method
    return Report (list);
}

Good example (dependency removed):

[Obsolete ("Limited to In32.MaxValue, use new Int64 ReportAll method")]
abstract int Report (IList list);
abstract long ReportAll (IList list);
// this method is correct but this changed the public API
public long GetCount ()
{
    return ReportAll (list);
}

Good example (decorated as [Obsolete]):

[Obsolete ("Limited to In32.MaxValue, use new Int64 ReportAll method")]
abstract int Report (IList list);
abstract long ReportAll (IList list);
[Obsolete ("Limited to In32.MaxValue, use new Int64 GetLongCount method")]
public int GetCount ()
{
    // this method is now correct since it is decorated with [Obsolete]
    return Report (list);
}
public long GetLongCount ()
{
    return ReportAll (list);
}

Notes

  • This rule is available since Gendarme 2.8

Source code

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

Clone this wiki locally