Last active
August 29, 2015 14:21
-
-
Save kpko/7e64cb14287bcf4197b9 to your computer and use it in GitHub Desktop.
.NET: ProjectionEqualityComparer<T>
This file contains hidden or 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 ProjectionEqualityComparer<T> : IEqualityComparer<T> | |
{ | |
Func<T, object> _projector; | |
public ProjectionEqualityComparer(Func<T, object> projector) | |
{ | |
this._projector = projector; | |
} | |
public bool Equals(T x, T y) | |
{ | |
if (x == null || y == null) return (x == null && y == null); | |
return object.Equals(_projector(x), _projector(y)); | |
} | |
public int GetHashCode(T obj) | |
{ | |
return _projector(obj).GetHashCode(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment