Making a base
call when overriding a method is generally a good idea, but not in the case of GetHashCode
and Equals
for classes that directly extend Object
.
These methods are based on the object’s reference, meaning that no two objects that use those base
methods can be equal or have the same
hash.
Exceptions
This rule doesn’t report on guard conditions checking for reference equality. For example:
public override bool Equals(object obj)
{
if (base.Equals(obj)) // Compliant, it's a guard condition.
{
return true;
}
...
}