mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 12:07:05 +00:00
Initial commit of PropertyComparer
This commit is contained in:
parent
e806b7c4c2
commit
0924002024
3 changed files with 33 additions and 2 deletions
30
ICD.Common.Utils/Comparers/PropertyComparer.cs
Normal file
30
ICD.Common.Utils/Comparers/PropertyComparer.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ICD.Common.Utils.Comparers
|
||||||
|
{
|
||||||
|
public sealed class PropertyComparer<TParent, TProperty> : IComparer<TParent>
|
||||||
|
{
|
||||||
|
private readonly IComparer<TProperty> m_Comparer;
|
||||||
|
private readonly Func<TParent, TProperty> m_GetProperty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
/// <param name="getProperty"></param>
|
||||||
|
public PropertyComparer(IComparer<TProperty> comparer, Func<TParent, TProperty> getProperty)
|
||||||
|
{
|
||||||
|
m_Comparer = comparer;
|
||||||
|
m_GetProperty = getProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Compare(TParent x, TParent y)
|
||||||
|
{
|
||||||
|
TProperty a = m_GetProperty(x);
|
||||||
|
TProperty b = m_GetProperty(y);
|
||||||
|
|
||||||
|
return m_Comparer.Compare(a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace ICD.Common.Utils.Extensions
|
namespace ICD.Common.Utils.Comparers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows for comparing items based on some property.
|
/// Allows for comparing items based on some property.
|
||||||
|
|
@ -74,6 +74,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Attributes\AbstractIcdAttribute.cs" />
|
<Compile Include="Attributes\AbstractIcdAttribute.cs" />
|
||||||
|
<Compile Include="Comparers\PropertyComparer.cs" />
|
||||||
<Compile Include="ConsoleColor.cs" />
|
<Compile Include="ConsoleColor.cs" />
|
||||||
<Compile Include="EventArguments\BoolEventArgs.cs" />
|
<Compile Include="EventArguments\BoolEventArgs.cs" />
|
||||||
<Compile Include="EventArguments\CharEventArgs.cs" />
|
<Compile Include="EventArguments\CharEventArgs.cs" />
|
||||||
|
|
@ -87,7 +88,7 @@
|
||||||
<None Include="ObfuscationSettings.cs" />
|
<None Include="ObfuscationSettings.cs" />
|
||||||
<Compile Include="Extensions\ByteExtensions.cs" />
|
<Compile Include="Extensions\ByteExtensions.cs" />
|
||||||
<Compile Include="Extensions\ListExtensions.cs" />
|
<Compile Include="Extensions\ListExtensions.cs" />
|
||||||
<Compile Include="Extensions\PropertyEqualityComparer.cs" />
|
<Compile Include="Comparers\PropertyEqualityComparer.cs" />
|
||||||
<Compile Include="ProcessorUtils.SimplSharp.cs" />
|
<Compile Include="ProcessorUtils.SimplSharp.cs" />
|
||||||
<Compile Include="ProcessorUtils.Standard.cs" />
|
<Compile Include="ProcessorUtils.Standard.cs" />
|
||||||
<Compile Include="ProgramUtils.SimplSharp.cs" />
|
<Compile Include="ProgramUtils.SimplSharp.cs" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue