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.
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.
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.SequenceEqualto determine equality. This caused the above test to fail as theLevel1objects were different instances despite the fact thatMemberwiseEqualityConverter<Level1>.ByProperties.Equalswould have returned true if used to compare them.This PR introduces new
ByFieldsRecursiveandByPropertiesRecursiveproperties toMemberwiseEqualityComparer<T>which (via an additionalMemberwiseEqualityModeparameter 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