Created
October 8, 2019 13:07
-
-
Save parsalotfy/3209ef2e71255773342b99cab9700f32 to your computer and use it in GitHub Desktop.
A generic equality comparer for type of T.
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
using System; | |
using System.Collections.Generic; | |
namespace SomeNameSpace | |
{ | |
public class TEqualityComparer<T> : EqualityComparer<T> | |
{ | |
private TEqualityComparer() | |
{ | |
} | |
public TEqualityComparer(Func<T,T,bool> equalsMethod, Func<T, int> getHashCodeMethod) | |
{ | |
EqualsMethod=equalsMethod; | |
GetHashCodeMethod=getHashCodeMethod; | |
} | |
public Func<T,T,bool> EqualsMethod { get; } | |
public Func<T, int> GetHashCodeMethod { get; } | |
public override bool Equals(T x, T y) | |
{ | |
return EqualsMethod(x,y); | |
} | |
public override int GetHashCode(T t) | |
{ | |
return GetHashCodeMethod(t); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment