From a0f8590f9cba7bdde5d9b661a7b836e124da99e9 Mon Sep 17 00:00:00 2001 From: Antony Male Date: Thu, 1 May 2014 17:45:34 +0100 Subject: [PATCH] Add LambdaComparer --- Stylet/LambdaComparer.cs | 36 ++++++++++++++++++++++++++++++++++++ Stylet/Stylet.csproj | 4 +++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Stylet/LambdaComparer.cs diff --git a/Stylet/LambdaComparer.cs b/Stylet/LambdaComparer.cs new file mode 100644 index 0000000..83bda6b --- /dev/null +++ b/Stylet/LambdaComparer.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stylet +{ + /// + /// IEqualityComparer{T} implementation which uses a Lambda + /// + /// + public class LambdaComparer : IEqualityComparer + { + Func comparer; + + /// + /// Create a new LambdaComparer{T} + /// + /// Comparer, which takes two {T} instances and returns true if they are equal + public LambdaComparer(Func comparer) + { + this.comparer = comparer; + } + + public bool Equals(T x, T y) + { + return this.comparer(x, y); + } + + public int GetHashCode(T obj) + { + return obj.GetHashCode(); + } + } +} diff --git a/Stylet/Stylet.csproj b/Stylet/Stylet.csproj index a3355a6..b086f89 100644 --- a/Stylet/Stylet.csproj +++ b/Stylet/Stylet.csproj @@ -48,7 +48,9 @@ - + + Code +