amis92 / RecordGenerator

C# immutable records generator
https://amis92.github.io/RecordGenerator/
MIT License
72 stars 10 forks source link

Equality implementation #75

Open amis92 opened 5 years ago

amis92 commented 5 years ago

I thought we agreed to use direct operator equality/valuetuple equality. That might come later.

Originally posted by @amis92 in https://github.com/amis92/RecordGenerator/pull/56


There are a couple of areas where we can certainly improve. Let's list them and discuss them.

amis92 commented 5 years ago

Found a problem as well, GeneratedCodeAttribute isn't applied on generated operator overloads (==/!=)

edit: moved to #77

amis92 commented 4 years ago

operator == should defer to direct left.Equals(right) call instead of using EqualityComparer.

This could be an optimization when we know we implement ObjectEquals and/or EquatableEquals. If not, we could probably check if the input class already implements either and if so, use that as well.

Prioritization of calls should be:

  1. IEquatable<T>.Equals(T) if interface is implemented (by us or not)
  2. object.Equals(object) if overridden
  3. EqualityComparer<T>.Equals(T, T) as a fallback