mirror of https://github.com/AMT-Cheif/Stylet.git
Add LambdaComparer
This commit is contained in:
parent
d0c62a6f15
commit
a0f8590f9c
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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" />
|
||||||
|
|
Loading…
Reference in New Issue