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

Generate Relational Comparer

Last modified: 21 July 2022

ReSharper | Edit | Generate Code | Relational Comparer

Alt+Insert | Relational Comparer (ReSharper_GenerateRelationalComparer)

ReSharper helps you create a nested comparer class derived from Comparer<T> using selected fields and properties. In addition to choosing a string comparison algorithm and generating null checks, you can opt for generating a static property that will expose the comparer class to consumers.

In the example below, this command is used to generate a relational comparer that takes into account int _birthYear and string _name fields when to compare objects of the Person class.

This feature is supported in the following languages and technologies:

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by language section.