Skip to content

Gendarme.Rules.Design.Linq.AvoidExtensionMethodOnSystemObjectRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

AvoidExtensionMethodOnSystemObjectRule

Assembly: Gendarme.Rules.Design.Linq
Version: 2.10

Description

Extension methods should not be used to extend System.Object. Such extension methods cannot be consumed by some languages, like VB.NET, which use late-binding on System.Object instances.

Examples

Bad example:

public static class Extensions {
    public static string ToDebugString (this object self)
    {
        return String.Format ("'{0}', type '{1}', hashcode: {2}",
        self.ToString (), self.GetType (), self.GetHashCode ());
    }
}

Good example:

public static class Extensions {
    public static string ToDebugString (this DateTime self)
    {
        return String.Format ("'{0}', type '{1}', hashcode: {2}",
        self.ToString (), self.GetType (), self.GetHashCode ());
    }
}

Notes

  • This rule is available since Gendarme 2.2
Clone this wiki locally