Browse Source
This makes the default references (System.Linq.dll etc.) available in code completion (previously we were only showing types from mscorlib)pull/24/head
4 changed files with 66 additions and 2 deletions
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Util |
||||
{ |
||||
public static class KeyComparer |
||||
{ |
||||
public static KeyComparer<TElement, TKey> Create<TElement, TKey>(Func<TElement, TKey> keySelector) |
||||
{ |
||||
return new KeyComparer<TElement, TKey>(keySelector, Comparer<TKey>.Default, EqualityComparer<TKey>.Default); |
||||
} |
||||
} |
||||
|
||||
public class KeyComparer<TElement, TKey> : IComparer<TElement>, IEqualityComparer<TElement> |
||||
{ |
||||
readonly Func<TElement, TKey> keySelector; |
||||
readonly IComparer<TKey> keyComparer; |
||||
readonly IEqualityComparer<TKey> keyEqualityComparer; |
||||
|
||||
public KeyComparer(Func<TElement, TKey> keySelector, IComparer<TKey> keyComparer, IEqualityComparer<TKey> keyEqualityComparer) |
||||
{ |
||||
this.keySelector = keySelector; |
||||
this.keyComparer = keyComparer; |
||||
this.keyEqualityComparer = keyEqualityComparer; |
||||
} |
||||
|
||||
public int Compare(TElement x, TElement y) |
||||
{ |
||||
return keyComparer.Compare(keySelector(x), keySelector(y)); |
||||
} |
||||
|
||||
public bool Equals(TElement x, TElement y) |
||||
{ |
||||
return keyEqualityComparer.Equals(keySelector(x), keySelector(y)); |
||||
} |
||||
|
||||
public int GetHashCode(TElement obj) |
||||
{ |
||||
return keyEqualityComparer.GetHashCode(keySelector(obj)); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue