A C# source generator that automatically implements IEquatable<T>, Equals, and GetHashCode using attributes.
Generator.Equals is a C# source generator that automatically implements the `IEquatable<T>` interface, along with `Equals` and `GetHashCode` methods, using attributes. It solves the problem of writing and maintaining correct, efficient equality logic, which is tedious and error-prone when done manually. The generator produces the code at compile time, ensuring best practices and eliminating boilerplate.
C# developers working on projects where value equality is important, such as those using domain models, data transfer objects, or any type that needs correct `Equals` and `GetHashCode` implementations.
Developers choose Generator.Equals because it drastically reduces manual coding and potential bugs in equality logic, supports complex scenarios like collections and inheritance out of the box, and provides detailed diff reporting, all through a simple, declarative attribute-based API.
A source code generator for automatically implementing IEquatable<T> using only attributes.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Marking a type with [Equatable] automatically generates IEquatable<T>, Equals, and GetHashCode, eliminating tedious and error-prone manual coding, as shown in the record example.
Supports arrays, lists, dictionaries, and sets with attributes like [OrderedEquality] and [SetEquality], enabling deep value-based comparisons out of the box.
Offers attributes for string comparison, numeric precision, references, and custom comparers, allowing fine-grained control without rewriting entire equality logic.
Correctly chains base.Equals() across hierarchies and inherits attributes from overridden properties, ensuring deep equality without manual boilerplate, as detailed in the migration notes.
Provides an Inequalities() method that returns detailed member-level differences with paths into nested objects and collections, useful for debugging and auditing.
Requires setting LangVersion to 9.0 or higher, which can block adoption in legacy projects or environments with fixed toolchains.
Developers must learn and correctly apply multiple attributes (e.g., [CustomEquality], [PrecisionEquality]), which can be overkill for simple types compared to hand-written code.
As a compile-time source generator, it cannot adapt to runtime type changes or dynamic objects, limiting use in highly reflective or plugin-based architectures.
Features like collection comparisons and structured diffs add overhead; for instance, [SetEquality] has hashing limitations and can be expensive for large collections.