Equ icon indicating copy to clipboard operation
Equ copied to clipboard

Use MemberwiseEqualityComparer as external comparer

Open xmedeko opened this issue 7 years ago • 2 comments

I use MemberwiseEqualityComparer for an external class, which I cannot change the code. It works great. However, I need to ommit a certain property, but I cannot add [MemberwiseEqualityIgnore] attribute to the external class code.

xmedeko avatar Sep 05 '18 17:09 xmedeko

Could maybe add a way to pass in a custom filter function that could filter out unwanted properties from classes you can't add annotations to? If you can think of a decent interface I can try implementing it on my fork when I have time.

ruler501 avatar Jul 14 '19 18:07 ruler501

You should be able to use MemberwiseEqualityComparer<T>.Custom(), see https://github.com/thedmi/Equ/blob/master/Sources/Equ/MemberwiseEqualityComparer.cs#L49. This factory method takes an EqualityFunctionGenerator. That class can be configured with selector functions (see constructor). You can use the selector functions to include/exclude properties, so for your case you could e.g. filter based on the property name.

thedmi avatar Jul 23 '19 08:07 thedmi