Created
September 25, 2013 18:29
-
-
Save millimoose/6703916 to your computer and use it in GitHub Desktop.
The last equality comparer implementation you'll need
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PropertyEqualityComparer<TItem> : EqualityComparer<TItem> | |
{ | |
readonly Func<TItem, object> _getter; | |
public PropertyEqualityComparer(Func<TItem, object> getter) | |
{ | |
_getter = getter; | |
} | |
public override bool Equals(TItem x, TItem y) | |
{ | |
return _getter(x).Equals(_getter(y)); | |
} | |
public override int GetHashCode(TItem obj) | |
{ | |
return _getter(obj).GetHashCode(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment