Skip to content

Instantly share code, notes, and snippets.

@millimoose
Created September 25, 2013 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save millimoose/6703916 to your computer and use it in GitHub Desktop.
Save millimoose/6703916 to your computer and use it in GitHub Desktop.
The last equality comparer implementation you'll need
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