6 using System.Collections.Generic;
17 ICollection<TElement>,
18 IEnumerable<TElement>,
21 private readonly HashSet<TElement> underlyingSet;
25 Debug.Assert(underlyingSet != null,
"underlyingSet cannot be null.");
27 this.underlyingSet = underlyingSet;
32 get {
return underlyingSet.Count; }
35 bool ICollection<TElement>.IsReadOnly
40 void ICollection<TElement>.Add(TElement item)
42 throw NewWriteDeniedException();
45 void ICollection<TElement>.Clear()
47 throw NewWriteDeniedException();
52 return underlyingSet.Contains(item);
55 public void CopyTo(TElement[] array,
int arrayIndex)
57 underlyingSet.CopyTo(array, arrayIndex);
62 return underlyingSet.GetEnumerator();
65 bool ICollection<TElement>.Remove(TElement item)
67 throw NewWriteDeniedException();
70 IEnumerator IEnumerable.GetEnumerator()
72 return underlyingSet.GetEnumerator();
75 private NotSupportedException NewWriteDeniedException()
77 return new NotSupportedException(
"ReadOnlyHashSet<TElement> is not directly writable.");