All rules
CA2231Usage Enabled by default: As suggestion

Overload operator equals on overriding ValueType.Equals

Overload operator equals on overriding ValueType.Equals

Microsoft docs

Description

In most programming languages, there is no default implementation of the equality operator (==) for value types. If your programming language supports operator overloads, you should consider implementing the equality operator. Its behavior should be identical to that of System.Object.Equals.

You cannot use the default equality operator in an overloaded implementation of the equality operator. Doing so will cause a stack overflow. To implement the equality operator, use the Object.Equals method in your implementation. For example:

Cause

A value type overrides System.Object.Equals but does not implement the equality operator.

By default, this rule only looks at externally visible types, but this is configurable.

How to fix violations

To fix a violation of this rule, implement the equality operator.

Example

if (Object.ReferenceEquals(left, null))
    return Object.ReferenceEquals(right, null);
return left.Equals(right);

When to suppress

It is safe to suppress a warning from this rule; however, we recommend that you provide the equality operator if possible.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0