Add LambdaComparer

This commit is contained in:
Antony Male 2014-05-01 17:45:34 +01:00
parent d0c62a6f15
commit a0f8590f9c
2 changed files with 39 additions and 1 deletions

36
Stylet/LambdaComparer.cs Normal file
View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stylet
{
/// <summary>
/// IEqualityComparer{T} implementation which uses a Lambda
/// </summary>
/// <typeparam name="T"></typeparam>
public class LambdaComparer<T> : IEqualityComparer<T>
{
Func<T, T, bool> comparer;
/// <summary>
/// Create a new LambdaComparer{T}
/// </summary>
/// <param name="comparer">Comparer, which takes two {T} instances and returns true if they are equal</param>
public LambdaComparer(Func<T, T, bool> comparer)
{
this.comparer = comparer;
}
public bool Equals(T x, T y)
{
return this.comparer(x, y);
}
public int GetHashCode(T obj)
{
return obj.GetHashCode();
}
}
}

View File

@ -48,7 +48,9 @@
<Compile Include="IValidationAdapter.cs" /> <Compile Include="IValidationAdapter.cs" />
<Compile Include="LabelledValue.cs" /> <Compile Include="LabelledValue.cs" />
<Compile Include="INotifyPropertyChangedDispatcher.cs" /> <Compile Include="INotifyPropertyChangedDispatcher.cs" />
<Compile Include="LambdaComparer.cs" /> <Compile Include="LambdaComparer.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="StyletConductorExtensions.cs" /> <Compile Include="StyletConductorExtensions.cs" />
<Compile Include="ValidatingModelBase.cs" /> <Compile Include="ValidatingModelBase.cs" />
<Compile Include="WeakEventManager.cs" /> <Compile Include="WeakEventManager.cs" />