Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 16, 2024

Conversation

danielcweber
Copy link
Contributor

@danielcweber danielcweber commented Aug 13, 2024

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
Copy link
Owner

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

@danielcweber danielcweber force-pushed the AvoidObjectEquals branch 2 times, most recently from 2b082e3 to a14ccc5 Compare August 16, 2024 09:34
@danielcweber
Copy link
Contributor Author

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

@danielcweber danielcweber changed the title [WIP] Don't call object.Equals() from '=='-operators but use Equals implementations on the type. Don't call object.Equals() from '=='-operators but use Equals implementations on the type. Aug 16, 2024
Copy link
Owner

@SteveDunn SteveDunn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for this contribution! Much appreciated.

@SteveDunn SteveDunn merged commit 3b3c04f into SteveDunn:main Aug 16, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants