Being somewhat lazy about implementing lots of IEqualityComparers, and given that I couldn\'t easily edit class implementations of object being compared, I went with the fol
Try this code:
public class GenericCompare : IEqualityComparer where T : class
{
private Func _expr { get; set; }
public GenericCompare(Func expr)
{
this._expr = expr;
}
public bool Equals(T x, T y)
{
var first = _expr.Invoke(x);
var sec = _expr.Invoke(y);
if (first != null && first.Equals(sec))
return true;
else
return false;
}
public int GetHashCode(T obj)
{
return obj.GetHashCode();
}
}
Example: collection = collection.Except(ExistedDataEles, new GenericCompare(x=>x.Id)).ToList();