|
7 | 7 |
|
8 | 8 | namespace Microsoft.PowerShell.CrossCompatibility |
9 | 9 | { |
| 10 | + /// <summary> |
| 11 | + /// A readonly set implementation that has set semantics and functions but is immutable. |
| 12 | + /// </summary> |
| 13 | + /// <typeparam name="T">The type of items in the set.</typeparam> |
10 | 14 | public class ReadOnlySet<T> : IEnumerable<T>, IReadOnlyCollection<T>, ISet<T> |
11 | 15 | { |
12 | 16 | private readonly HashSet<T> _backingSet; |
13 | 17 |
|
| 18 | + /// <summary> |
| 19 | + /// Construct a new ReadOnlySet around the given items. |
| 20 | + /// </summary> |
| 21 | + /// <param name="items">The set elements.</param> |
14 | 22 | public ReadOnlySet(IEnumerable<T> items) |
15 | 23 | { |
16 | 24 | _backingSet = new HashSet<T>(items); |
17 | 25 | } |
18 | 26 |
|
| 27 | + /// <summary> |
| 28 | + /// Construct a new ReadOnlySet around the given items with the given comparer. |
| 29 | + /// </summary> |
| 30 | + /// <param name="items">The set elements.</param> |
| 31 | + /// <param name="itemComparer">The comparer to evaluate item equality.</param> |
19 | 32 | public ReadOnlySet(IEnumerable<T> items, IEqualityComparer<T> itemComparer) |
20 | 33 | { |
21 | 34 | _backingSet = new HashSet<T>(items, itemComparer); |
22 | 35 | } |
23 | 36 |
|
| 37 | + /// <summary> |
| 38 | + /// The number of items in the set. |
| 39 | + /// </summary> |
24 | 40 | public int Count => _backingSet.Count; |
25 | 41 |
|
| 42 | + /// <summary> |
| 43 | + /// Indicates that this set is readonly. |
| 44 | + /// </summary> |
26 | 45 | public bool IsReadOnly => true; |
27 | 46 |
|
| 47 | + /// <summary> |
| 48 | + /// DO NOT USE. |
| 49 | + /// </summary> |
28 | 50 | public bool Add(T item) |
29 | 51 | { |
30 | 52 | throw new InvalidOperationException("Cannot add item to readonly set"); |
31 | 53 | } |
32 | 54 |
|
| 55 | + /// <summary> |
| 56 | + /// DO NOT USE. |
| 57 | + /// </summary> |
33 | 58 | public void Clear() |
34 | 59 | { |
35 | 60 | throw new InvalidOperationException("Cannot modify a readonly set"); |
36 | 61 | } |
37 | 62 |
|
| 63 | + /// <summary> |
| 64 | + /// Indicates whether a given object is in the set. |
| 65 | + /// </summary> |
| 66 | + /// <param name="item">The object to check the set for.</param> |
| 67 | + /// <returns>True if the object is in the set, false otherwise.</returns> |
38 | 68 | public bool Contains(T item) |
39 | 69 | { |
40 | 70 | return _backingSet.Contains(item); |
41 | 71 | } |
42 | 72 |
|
| 73 | + /// <inheritdoc/> |
43 | 74 | public void CopyTo(T[] array, int arrayIndex) |
44 | 75 | { |
45 | 76 | _backingSet.CopyTo(array, arrayIndex); |
46 | 77 | } |
47 | 78 |
|
| 79 | + /// <summary> |
| 80 | + /// DO NOT USE. |
| 81 | + /// </summary> |
48 | 82 | public void ExceptWith(IEnumerable<T> other) |
49 | 83 | { |
50 | 84 | throw new InvalidOperationException("Cannot modify a readonly set"); |
51 | 85 | } |
52 | 86 |
|
| 87 | + /// <inheritdoc/> |
53 | 88 | public IEnumerator<T> GetEnumerator() |
54 | 89 | { |
55 | 90 | return _backingSet.GetEnumerator(); |
56 | 91 | } |
57 | 92 |
|
| 93 | + /// <summary> |
| 94 | + /// DO NOT USE. |
| 95 | + /// </summary> |
58 | 96 | public void IntersectWith(IEnumerable<T> other) |
59 | 97 | { |
60 | 98 | throw new InvalidOperationException("Cannot modify a readonly set"); |
61 | 99 | } |
62 | 100 |
|
| 101 | + /// <inheritdoc/> |
63 | 102 | public bool IsProperSubsetOf(IEnumerable<T> other) |
64 | 103 | { |
65 | 104 | return _backingSet.IsProperSubsetOf(other); |
66 | 105 | } |
67 | 106 |
|
| 107 | + /// <inheritdoc/> |
68 | 108 | public bool IsProperSupersetOf(IEnumerable<T> other) |
69 | 109 | { |
70 | 110 | return _backingSet.IsProperSupersetOf(other); |
71 | 111 | } |
72 | 112 |
|
| 113 | + /// <inheritdoc/> |
73 | 114 | public bool IsSubsetOf(IEnumerable<T> other) |
74 | 115 | { |
75 | 116 | return _backingSet.IsSubsetOf(other); |
76 | 117 | } |
77 | 118 |
|
| 119 | + /// <inheritdoc/> |
78 | 120 | public bool IsSupersetOf(IEnumerable<T> other) |
79 | 121 | { |
80 | 122 | return _backingSet.IsSupersetOf(other); |
81 | 123 | } |
82 | 124 |
|
| 125 | + /// <inheritdoc/> |
83 | 126 | public bool Overlaps(IEnumerable<T> other) |
84 | 127 | { |
85 | 128 | return _backingSet.Overlaps(other); |
86 | 129 | } |
87 | 130 |
|
| 131 | + /// <summary> |
| 132 | + /// DO NOT USE. |
| 133 | + /// </summary> |
88 | 134 | public bool Remove(T item) |
89 | 135 | { |
90 | 136 | throw new InvalidOperationException("Cannot modify a readonly set"); |
91 | 137 | } |
92 | 138 |
|
| 139 | + /// <inheritdoc/> |
93 | 140 | public bool SetEquals(IEnumerable<T> other) |
94 | 141 | { |
95 | 142 | return _backingSet.SetEquals(other); |
96 | 143 | } |
97 | 144 |
|
| 145 | + /// <summary> |
| 146 | + /// DO NOT USE. |
| 147 | + /// </summary> |
98 | 148 | public void SymmetricExceptWith(IEnumerable<T> other) |
99 | 149 | { |
100 | 150 | throw new InvalidOperationException("Cannot modify a readonly set"); |
101 | 151 | } |
102 | 152 |
|
| 153 | + /// <summary> |
| 154 | + /// DO NOT USE. |
| 155 | + /// </summary> |
103 | 156 | public void UnionWith(IEnumerable<T> other) |
104 | 157 | { |
105 | 158 | throw new InvalidOperationException("Cannot modify a readonly set"); |
106 | 159 | } |
107 | 160 |
|
| 161 | + /// <summary> |
| 162 | + /// DO NOT USE. |
| 163 | + /// </summary> |
108 | 164 | void ICollection<T>.Add(T item) |
109 | 165 | { |
110 | 166 | throw new InvalidOperationException("Cannot modify a readonly set"); |
111 | 167 | } |
112 | 168 |
|
| 169 | + /// <inheritdoc/> |
113 | 170 | IEnumerator IEnumerable.GetEnumerator() |
114 | 171 | { |
115 | 172 | return ((IEnumerable)_backingSet).GetEnumerator(); |
|
0 commit comments