RecordGenerator icon indicating copy to clipboard operation
RecordGenerator copied to clipboard

Equality implementation

Open amis92 opened this issue 6 years ago • 2 comments

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 avatar Aug 05 '19 12:08 amis92

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

edit: moved to #77

amis92 avatar Aug 06 '19 09:08 amis92

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

amis92 avatar Jan 06 '20 12:01 amis92