ValeraT1982 / ObjectsComparer

C# Framework provides mechanism to compare complex objects, allows to override comparison rules for specific properties and types.
MIT License
352 stars 86 forks source link

Ignore Members to compare in a List #59

Open ADRI082 opened 5 months ago

ADRI082 commented 5 months ago

Hello, I have been trying to find out how to ignore the comparison of several members but it seems that the ignoreMember method does not work properly or maybe I am doing something wrong. Could you give me a hand with this? Example :

Class A { public string example1 {get;set;} public string example2 {get;set;} public B classB {get;set;} }

Class B { public example3 {get;set;} public example4 {get;set;} }

var comparer = new ObjectsComparer.Comparer<List>(); comparer.IgnoreMember(() => new A().example1);

This example would not work. What Do I have to suppossed to do? Thanks in advance!

ValeraT1982 commented 5 months ago

Can you please provide an example with actual and expected result? Are you comparing objects of type List or List?

ADRI082 commented 5 months ago

For example, I want to compare two list from Class A.

var firstList = new List(); var secondList = new List();

var comparer = new ObjectsComparer.Comparer<List>(); comparer.IgnoreMember(() => new A().example1);

This should not show me the comparisons of "example1" but it does.

How should I avoid members to compare when I am comparing two list of class A?

ValeraT1982 commented 5 months ago

example1 isn't a property of your "root" object. You need to use factory. Look at this example: https://github.com/ValeraT1982/ObjectsComparer?tab=readme-ov-file#example-2-persons-comparison