mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-14 04:05:04 +00:00
Initial commit of PropertyComparer
This commit is contained in:
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.Collections.Generic;
|
||||
|
||||
namespace ICD.Common.Utils.Extensions
|
||||
namespace ICD.Common.Utils.Comparers
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows for comparing items based on some property.
|
||||
@@ -74,6 +74,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Attributes\AbstractIcdAttribute.cs" />
|
||||
<Compile Include="Comparers\PropertyComparer.cs" />
|
||||
<Compile Include="ConsoleColor.cs" />
|
||||
<Compile Include="EventArguments\BoolEventArgs.cs" />
|
||||
<Compile Include="EventArguments\CharEventArgs.cs" />
|
||||
@@ -87,7 +88,7 @@
|
||||
<None Include="ObfuscationSettings.cs" />
|
||||
<Compile Include="Extensions\ByteExtensions.cs" />
|
||||
<Compile Include="Extensions\ListExtensions.cs" />
|
||||
<Compile Include="Extensions\PropertyEqualityComparer.cs" />
|
||||
<Compile Include="Comparers\PropertyEqualityComparer.cs" />
|
||||
<Compile Include="ProcessorUtils.SimplSharp.cs" />
|
||||
<Compile Include="ProcessorUtils.Standard.cs" />
|
||||
<Compile Include="ProgramUtils.SimplSharp.cs" />
|
||||
|
||||
Reference in New Issue
Block a user