SteveDunn / Vogen

A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Apache License 2.0
782 stars 46 forks source link

Don't call object.Equals() from '=='-operators but use Equals implementations on the type. #655

Closed danielcweber closed 1 month ago

danielcweber commented 1 month ago

This is a work in progress just to show the issue/possible solution and start a discussion. No test, no snapshots yet.

Currently, the == operators call the static object.Equals method that operates on object parameters. This induces boxing (in case the value object is a struct) and can be avoided since the the value object already defines correctly typed Equals methods. Subsequently, this PR also changes the == operator implementation when comparison is done with an underlying type and establishes symmetry for the != operators, ie. x != y should just be !(x == y).

SteveDunn commented 1 month ago

Thanks for the contribution @danielcweber - this makes perfect sense!

danielcweber commented 1 month ago

Added snapshots. Still a WIP because this PR is based on #656.