Skip to content

Instantly share code, notes, and snippets.

@alfredodev
Created June 18, 2014 10:46
Show Gist options
  • Select an option

  • Save alfredodev/db10370efc03f647378f to your computer and use it in GitHub Desktop.

Select an option

Save alfredodev/db10370efc03f647378f to your computer and use it in GitHub Desktop.
public class PredicateEqualityComparer<T> : EqualityComparer<T>
{
private readonly Func<T, T, bool> predicate;
public PredicateEqualityComparer(Func<T, T, bool> predicate)
{
this.predicate = predicate;
}
public override bool Equals(T x, T y)
{
if (x != null)
{
return ((y != null) && predicate(x, y));
}
if (y != null)
{
return false;
}
return true;
}
public override int GetHashCode(T obj)
{
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment