mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 13:45:05 +00:00
Making FuncComparer actually work
This commit is contained in:
@@ -653,14 +653,15 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shim to
|
/// Gets distinct elements from the sequence based on given callbacks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <param name="extends"></param>
|
/// <param name="extends"></param>
|
||||||
/// <param name="comparer"></param>
|
/// <param name="comparer"></param>
|
||||||
|
/// <param name="getHashCode"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static IEnumerable<T> Distinct<T>(this IEnumerable<T> extends, Func<T, T, bool> comparer)
|
public static IEnumerable<T> Distinct<T>(this IEnumerable<T> extends, Func<T, T, bool> comparer, Func<T, int> getHashCode)
|
||||||
{
|
{
|
||||||
if (extends == null)
|
if (extends == null)
|
||||||
throw new ArgumentNullException("extends");
|
throw new ArgumentNullException("extends");
|
||||||
@@ -668,7 +669,7 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
if (comparer == null)
|
if (comparer == null)
|
||||||
throw new ArgumentNullException("comparer");
|
throw new ArgumentNullException("comparer");
|
||||||
|
|
||||||
return extends.Distinct(new FuncComparer<T>(comparer));
|
return extends.Distinct(new FuncComparer<T>(comparer, getHashCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -10,14 +10,17 @@ namespace ICD.Common.Utils
|
|||||||
public sealed class FuncComparer<T> : IEqualityComparer<T>
|
public sealed class FuncComparer<T> : IEqualityComparer<T>
|
||||||
{
|
{
|
||||||
private readonly Func<T, T, bool> m_Comparer;
|
private readonly Func<T, T, bool> m_Comparer;
|
||||||
|
private readonly Func<T, int> m_GetHashCode;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="comparer"></param>
|
/// <param name="comparer"></param>
|
||||||
public FuncComparer(Func<T, T, bool> comparer)
|
/// <param name="getHashCode"></param>
|
||||||
|
public FuncComparer(Func<T, T, bool> comparer, Func<T, int> getHashCode)
|
||||||
{
|
{
|
||||||
m_Comparer = comparer;
|
m_Comparer = comparer;
|
||||||
|
m_GetHashCode = getHashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(T x, T y)
|
public bool Equals(T x, T y)
|
||||||
@@ -27,7 +30,7 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
public int GetHashCode(T obj)
|
public int GetHashCode(T obj)
|
||||||
{
|
{
|
||||||
return obj.GetHashCode();
|
return m_GetHashCode(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user