-
Notifications
You must be signed in to change notification settings - Fork 89
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
Compare two objects with more than one list property #58
Comments
I just tried to implement custom Comparer for every list property and it works. |
Are types of the lists same? Can you give an example? |
No, the types are different, but all have an id property.
|
I create a class to implement custom Comparer making use of generics, and only have to add if statement in ComparersFactory for every type of lists. |
@huangyy21 you can inherit both classes from the same interface and use this interface in ComparersFactory instead of having separate if for each class. |
In my PR #47, you don't need to implement custom comparer at all. All you need to do is this: var settings = new ComparisonSettings();
settings.ConfigureListComparison(compareElementsByKey: true, compareUnequalLists: true);
var comparer = new Comparer<Formula>(settings);
var isEqual = comparer.Compare(formula1, formula2, out var differences); The complete test method: https://github.com/reponemec/ObjectsComparer/blob/35cd3fc60898ff44639146efe4efb9a108a5a5f7/ObjectsComparer/ObjectsComparer.Examples/Example4/Example4Tests_BuiltInKeyComparison.cs#L119 |
Thanks for reply. My memberPath needs more information, so it may be better to implement custom comparer. |
My memberPath needs more information, so it may be better to implement custom comparer. Absolutely, however the memberPath property can also be customized using ComparisonSettings: |
Hi,
Form example4, I have known how to compare objects with one list.
But if my object have more than one list, what should I do?
The text was updated successfully, but these errors were encountered: