17 using System.Collections;
18 using System.Collections.Generic;
19 using System.Collections.Specialized;
31 private readonly IEnumerator<T> _emptyEnumerator = Enumerable.Empty<T>().
GetEnumerator();
32 private readonly OrderedDictionary _set =
new OrderedDictionary();
34 private readonly List<T> _enumerator =
new List<T>();
35 private bool _refreshEnumerator;
57 void ICollection<T>.Add(T item)
61 throw new ArgumentNullException(nameof(item));
76 var otherSet = other.ToHashSet();
80 foreach (var item
in otherSet)
94 var otherSet = other.ToHashSet();
100 foreach (var item
in this)
102 if (!otherSet.Contains(item))
116 var otherSet = other.ToHashSet();
121 foreach (var item
in otherSet)
134 var otherSet = other.ToHashSet();
138 foreach (var item
in otherSet)
156 var otherSet = other.ToHashSet();
159 foreach (var item
in otherSet)
161 if (!_set.Contains(item))
168 return _set.Keys.Count == 0;
179 var otherSet = other.ToHashSet();
182 foreach (DictionaryEntry item
in _set)
184 if (!otherSet.Remove((T)item.Key))
202 var hasOther =
false;
203 var otherSet = other.ToHashSet();
206 foreach (DictionaryEntry item
in _set)
208 if (!otherSet.Remove((T)item.Key))
228 var hasOther =
false;
229 var otherSet = other.ToHashSet();
232 foreach (var item
in otherSet)
234 if (!_set.Contains(item))
243 return hasOther && _set.Keys.Count == 0;
254 var otherSet = other.ToHashSet();
258 foreach (var item
in otherSet)
260 if (_set.Contains(item))
277 var otherSet = other.ToHashSet();
280 foreach (DictionaryEntry item
in _set)
282 if (!otherSet.Remove((T) item.Key))
289 return otherSet.Count == 0;
299 return AddImpl(item);
309 _refreshEnumerator =
true;
321 return item !=
null && _set.Contains(item);
333 public void CopyTo(T[] array,
int arrayIndex)
337 foreach (DictionaryEntry item
in _set)
339 array[arrayIndex++] = (T) item.Key;
352 if (item !=
null && _set.Contains(item))
369 if (_refreshEnumerator)
372 foreach (DictionaryEntry item
in _set)
374 _enumerator.Add((T)item.Key);
377 _refreshEnumerator =
false;
380 return _enumerator.Count == 0 ? _emptyEnumerator : _enumerator.GetEnumerator();
388 IEnumerator IEnumerable.GetEnumerator()
393 private bool AddImpl(T item)
395 if (!_set.Contains(item))
397 _refreshEnumerator =
true;
398 _set.Add(item, item);
405 private void RemoveImpl(T item)
407 _refreshEnumerator =
true;