Skip to content

Gendarme.Rules.Design.OverrideEqualsMethodRule(2.10)

Sebastien Pouliot edited this page Jan 22, 2011 · 2 revisions

OverrideEqualsMethodRule

Assembly: Gendarme.Rules.Design
Version: 2.10

Description

This rule warns when a type overloads the equality == operator but does not override the Object.Equals method.

Examples

Bad example:

class DoesNotOverrideEquals {
    public static bool operator == (DoesNotOverloadOperatorEquals a, DoesNotOverloadOperatorEquals b)
    {
        return true;
    }
}

Good example:

class OverridesEquals {
    public static bool operator == (OverridesEquals a, OverridesEquals b)
    {
        return true;
    }
    public override bool Equals (object obj)
    {
        OverridesEquals other = (obj as OverridesEquals);
        if (other == null) {
            return false;
        }
        return (this == other);
    }
}
Clone this wiki locally