// Needed for NET40 #if !NET_4_6 using System; using System.Collections.Generic; using LinqInternal.Core; namespace LinqInternal.Collections { [Serializable] [System.Diagnostics.DebuggerNonUserCode] internal sealed partial class ExtendedReadOnlyCollection : IReadOnlyCollection, ICollection { private readonly ICollection _wrapped; public ExtendedReadOnlyCollection(ICollection wrapped) { if (wrapped == null) { throw new ArgumentNullException("wrapped"); } _wrapped = wrapped; } public IReadOnlyCollection AsReadOnly { get { return this; } } public int Count { get { return _wrapped.Count; } } bool ICollection.IsReadOnly { get { return true; } } public bool Contains(T item) { return _wrapped.Contains(item); } public bool Contains(T item, IEqualityComparer comparer) { return System.Linq.Enumerable.Contains(this, item, comparer); } public void CopyTo(T[] array, int arrayIndex) { _wrapped.CopyTo(array, arrayIndex); } public void CopyTo(T[] array) { _wrapped.CopyTo(array, 0); } public void CopyTo(T[] array, int arrayIndex, int countLimit) { Extensions.CanCopyTo(array, arrayIndex, countLimit); Extensions.CopyTo(this, array, arrayIndex, countLimit); } public IEnumerator GetEnumerator() { return _wrapped.GetEnumerator(); } void ICollection.Add(T item) { throw new NotSupportedException(); } void ICollection.Clear() { throw new NotSupportedException(); } bool ICollection.Remove(T item) { throw new NotSupportedException(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } public T[] ToArray() { var array = new T[_wrapped.Count]; CopyTo(array); return array; } } } #endif