forked from espresso3389/AdaptiveKeyboardConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaComparer.cs
More file actions
34 lines (29 loc) · 845 Bytes
/
LambdaComparer.cs
File metadata and controls
34 lines (29 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
using System.Linq;
namespace LambdaComparer
{
public class CompareSelector<T, TKey> : IEqualityComparer<T>
{
private readonly Func<T, TKey> selector;
public CompareSelector(Func<T, TKey> selector)
{
this.selector = selector;
}
public bool Equals(T x, T y)
{
return selector(x).Equals(selector(y));
}
public int GetHashCode(T obj)
{
return selector(obj).GetHashCode();
}
}
public static class ExtensionMethods
{
public static IEnumerable<T> Distinct<T, TKey>(this IEnumerable<T> source, Func<T, TKey> selector)
{
return source.Distinct(new CompareSelector<T, TKey>(selector));
}
}
}