c# - Validate values of all properties in list with a duplicate for custom method -
i need write method can compare 2 lists see whether there differences between two, without specifying property in 2 lists compare. instance cannot say:
var exceptlist = list1.where (r => r.name !list2.any( r2.name == r.name ))
the bold part needs dynamic can re-use method different types of lists. know following example won't work, need similar:
var r = myleftlist.where(p => !myrighttlist.any(p2 => p2.gettype().getproperties().getvalue(myleftlist.indexof(p2)) == p.gettype().getproperties().getvalue(myrighttlist.indexof(p))));
you can use except
extension method.
see msdn
being aware of point:
if want compare sequences of objects of custom data type, have implement iequalitycomparer generic interface in class.
Comments
Post a Comment