You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
5 years ago
|
// Needed for NET35 (ConditionalWeakTable)
|
||
|
#if !NET_4_6
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
|
using LinqInternal.Core;
|
||
|
|
||
|
namespace LinqInternal.Collections.Specialized
|
||
|
{
|
||
|
[System.Diagnostics.DebuggerNonUserCode]
|
||
|
internal class ConversionEqualityComparer<TInput, TOutput> : IEqualityComparer<TInput>
|
||
|
{
|
||
|
private readonly IEqualityComparer<TOutput> _comparer;
|
||
|
private readonly Func<TInput, TOutput> _converter;
|
||
|
|
||
|
public ConversionEqualityComparer(IEqualityComparer<TOutput> comparer, Func<TInput, TOutput> converter)
|
||
|
{
|
||
|
_comparer = comparer ?? EqualityComparer<TOutput>.Default;
|
||
|
if (converter == null)
|
||
|
{
|
||
|
throw new ArgumentNullException("converter");
|
||
|
}
|
||
|
_converter = converter;
|
||
|
}
|
||
|
|
||
|
public bool Equals(TInput x, TInput y)
|
||
|
{
|
||
|
return _comparer.Equals(_converter.Invoke(x), _converter.Invoke(y));
|
||
|
}
|
||
|
|
||
|
public int GetHashCode(TInput obj)
|
||
|
{
|
||
|
return _comparer.GetHashCode(_converter.Invoke(obj));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#endif
|