// Needed for NET40 #if !NET_4_6 using System; using System.Collections; using System.Collections.Generic; namespace LinqInternal.Collections.Specialized { [Serializable] internal sealed class KeyCollection : ICollection, ICollection, IReadOnlyCollection { private readonly IDictionary _wrapped; internal KeyCollection(IDictionary wrapped) { if (wrapped == null) { throw new ArgumentNullException("wrapped"); } _wrapped = wrapped; } public int Count { get { return _wrapped.Count; } } bool ICollection.IsSynchronized { get { return ((ICollection)_wrapped).IsSynchronized; } } object ICollection.SyncRoot { get { return ((ICollection)_wrapped).SyncRoot; } } bool ICollection.IsReadOnly { get { return true; } } public void CopyTo(TKey[] array, int arrayIndex) { Extensions.CanCopyTo(_wrapped.Count, array, arrayIndex); _wrapped.ConvertProgressive(pair => pair.Key).CopyTo(array, arrayIndex); } public IEnumerator GetEnumerator() { return _wrapped.ConvertProgressive(pair => pair.Key).GetEnumerator(); } void ICollection.CopyTo(Array array, int index) { ((ICollection)_wrapped).CopyTo(array, index); } void ICollection.Add(TKey item) { throw new NotSupportedException(); } void ICollection.Clear() { throw new NotSupportedException(); } bool ICollection.Contains(TKey item) { return _wrapped.ContainsKey(item); } bool ICollection.Remove(TKey item) { throw new NotSupportedException(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } } #endif