// Needed for NET40 #if !NET_4_6 using System; using System.Collections; using System.Collections.Generic; using LinqInternal.Core; namespace LinqInternal.Collections { [Serializable] [System.Diagnostics.DebuggerNonUserCode] [System.Diagnostics.DebuggerDisplay("Count={Count}")] #if FAT internal sealed class ExtendedSet : IExtendedSet, ICollection, ISet, ICloneable> { private readonly IReadOnlySet _readOnly; private readonly HashSet _wrapped; public ExtendedSet() { _wrapped = new HashSet(); _readOnly = new ExtendedReadOnlySet(this); } public ExtendedSet(IEnumerable prototype) { _wrapped = new HashSet(); _readOnly = new ExtendedReadOnlySet(this); this.AddRange(prototype); } public ExtendedSet(IEnumerable prototype, IEqualityComparer comparer) { _wrapped = new HashSet(comparer); _readOnly = new ExtendedReadOnlySet(this); this.AddRange(prototype); } public ExtendedSet(IEqualityComparer comparer) { _readOnly = new ExtendedReadOnlySet(this); _wrapped = new HashSet(comparer); } public IReadOnlySet AsReadOnly { get { return _readOnly; } } #else public sealed class ExtendedSet : ICloneable, ICollection, ISet { private readonly HashSet _wrapped; public ExtendedSet() { _wrapped = new HashSet(); } public ExtendedSet(IEnumerable prototype) { _wrapped = new HashSet(); this.AddRange(prototype); } public ExtendedSet(IEnumerable prototype, IEqualityComparer comparer) { _wrapped = new HashSet(comparer); this.AddRange(prototype); } public ExtendedSet(IEqualityComparer comparer) { _wrapped = new HashSet(comparer); } #endif public int Count { get { return _wrapped.Count; } } public bool IsReadOnly { get { return false; } } public bool Add(T item) { return _wrapped.Add(item); } public void Clear() { _wrapped.Clear(); } public ExtendedSet Clone() { return new ExtendedSet(this); } public bool Contains(T item) { return _wrapped.Contains(item); } public bool Contains(T item, IEqualityComparer comparer) { return System.Linq.Enumerable.Contains(_wrapped, item, comparer); } public void CopyTo(T[] array, int arrayIndex) { _wrapped.CopyTo(array, arrayIndex); } public void CopyTo(T[] array) { CopyTo(array, 0); } public void CopyTo(T[] array, int arrayIndex, int countLimit) { _wrapped.CopyTo(array, arrayIndex, countLimit); } public void ExceptWith(IEnumerable other) { Extensions.ExceptWith(this, other); } public IEnumerator GetEnumerator() { return _wrapped.GetEnumerator(); } #if !NETCOREAPP1_1 object ICloneable.Clone() { return Clone(); } #endif void ICollection.Add(T item) { Add(item); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void IntersectWith(IEnumerable other) { _wrapped.IntersectWith(other); } public bool IsProperSubsetOf(IEnumerable other) { return _wrapped.IsProperSubsetOf(other); } public bool IsProperSupersetOf(IEnumerable other) { return _wrapped.IsProperSupersetOf(other); } public bool IsSubsetOf(IEnumerable other) { return _wrapped.IsSubsetOf(other); } public bool IsSupersetOf(IEnumerable other) { return _wrapped.IsSupersetOf(other); } public bool Overlaps(IEnumerable other) { return _wrapped.Overlaps(other); } public bool Remove(T item) { return _wrapped.Remove(item); } public bool Remove(T item, IEqualityComparer comparer) { if (comparer == null) { comparer = EqualityComparer.Default; } foreach (var foundItem in _wrapped.RemoveWhereEnumerable(input => comparer.Equals(input, item))) { GC.KeepAlive(foundItem); return true; } return false; } public bool SetEquals(IEnumerable other) { return _wrapped.SetEquals(other); } public void SymmetricExceptWith(IEnumerable other) { _wrapped.SymmetricExceptWith(other); } public void UnionWith(IEnumerable other) { _wrapped.UnionWith(other); } } } #endif