-
Notifications
You must be signed in to change notification settings - Fork 6
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
Equ all the way down #25
base: master
Are you sure you want to change the base?
Conversation
…ter for comparing sets
…s` and `MemberwiseEqualityComparer<T>.ByProperties` by add a `MemberwiseEqualityMode` parameter to `EqualityFunctionGenerator` and adding new `MemberwiseEqualityComparer<T>.ByFieldsRecursive` and `MemberwiseEqualityComparer<T>.ByPropertiesRecursive` static properties.
|
||
private object CreateMemberwiseEqualityComparer(MemberwiseEqualityMode mode) | ||
{ | ||
var propertyName = mode switch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I've seen this syntax before. I haven't paid much attention to the new features for a few years though. What is it doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's C# 8.0's pattern matching: https://docs.microsoft.com/en-us/archive/msdn-magazine/2019/may/csharp-8-0-pattern-matching-in-csharp-8-0
This seems like a reasonable and useful change to me. |
…yComparer<T>.ByPropertyRecursive` now use MemberwiseEqualityComparer for nested objects instead of Object.Equals
Amazingly I hadn't realised Equ doesn't provided deep equality for nested objects either. Since @ruler501's last review I've added an additional commit which allows |
Needs documentation of the new features. |
Hi,
I encountered unexpected behaviour in Equ wherein the following (uncommented) unit test failed:
It turns out that, while properties were being used for equality comparision at the root level, collections properties were falling back to using
Enumerable.SequenceEqual
to determine equality. This caused the above test to fail as theLevel1
objects were different instances despite the fact thatMemberwiseEqualityConverter<Level1>.ByProperties.Equals
would have returned true if used to compare them.This PR introduces new
ByFieldsRecursive
andByPropertiesRecursive
properties toMemberwiseEqualityComparer<T>
which (via an additionalMemberwiseEqualityMode
parameter onEqualityFunctionGenerator
) causeElementwiseSequenceEqualityComparer<T>
to use the appropriateMemberwiseEqualityComparer<T>
instance to compare internal collections such that the following unit tests pass:I hope you will find this PR useful and worth merging into the Equ package. If, for some reason, you don't feel it's appropriate to add this functionality to the package, could you let me know so that I can build my own package encompasing it.
Thanks, Ian