C#


ROSLYN.DESIGN.CA1066 : Implement IEquatable when overriding Object.Equals (C#)

See Roslyn-Detected C# Warning Classes for more information.

Summary

When a type T overrides Object.Equals(object), the implementation must cast the object argument to the correct type T before performing the comparison. If the type implements IEquatable, and therefore offers the method T.Equals(T), and if the argument is known at compile time to be of type T, then the compiler can call IEquatable.Equals(T) instead of Object.Equals(object), and no cast is necessary, improving performance.

This check corresponds to Roslyn rule CA1066. For full rule details, see the Microsoft website: CA1066.

Properties

Class Name Implement IEquatable when overriding Object.Equals (C#)
Significance reliability
Mnemonic ROSLYN.DESIGN.CA1066
Categories None
Availability Available for C# only.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Implement IEquatable when overriding Object.Equals (C#)"

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.