JetBrains Rider
 
Get JetBrains Rider
You are viewing the documentation for an earlier version of JetBrains Rider.

Generate Equality Comparer

Last modified: 08 March 2021

Code | Generate | Equality Comparer

Alt+Insert | Equality Comparer

IEqualityComparer<T> is a generic .NET interface that allows implementing customized equality comparison for collections.

Creating a comparer class for your type is an alternative to creating Equals() and GetHashCode() methods for the type. The generated comparer class will implement the IEqualityComparer<T> interface and provide custom Equals() and GetHashCode()) methods.

JetBrains Rider provides the Generate equality comparer command to automate generation of the comparer class.

In the example below, this command is used to generate the comparer class based on _radius and _center fields.

Alternatively, you can write an empty comparer class that implements IEqualityComparer<T>, and then pick the corresponding quick-fix from the Alt+Enter menu:

JetBrains Rider: Generate equality comparer quick-fix