You've implemented IEqualityComparer<T>
, which is fine if you want to pass in an instance of your class to Distinct
:
var distinctList = MapGrid.Distinct(new MapsDescModel());
However a cleaner method is to implement IEquatable<T>
instead, since Distinct
will use that by default if you don't pass in an IEqualityComparer<T>
:
public class MapsDescModel : NotificationObject, IEqualityComparer<MapsDescModel>, IEquatable<MapsDescModel>
{
...
public bool Equals(MapsDescModel y)
{
return
this.Equals(this,y); // use definition from IEqualityComparer<T>
}
}
I would also recommend overriding object.Equals
and object.GetHashCode
for consistency, again leveraging the IEqualityComparer
methods if you like (or just converting the IEqualityComparer
methods to overrides if you decide you don't need them anymore).