Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Collection.cs
Go to the documentation of this file.
4
6
9[DebuggerDisplay("Count = {Count}")]
10[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
12{
13 private readonly IList<T> items;
14
15 public int Count => items.Count;
16
17 protected IList<T> Items => items;
18
19 public T this[int index]
20 {
21 get
22 {
23 return items[index];
24 }
25 set
26 {
27 if (items.IsReadOnly)
28 {
29 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
30 }
31 if ((uint)index >= (uint)items.Count)
32 {
34 }
36 }
37 }
38
40
41 bool ICollection.IsSynchronized => false;
42
43 object ICollection.SyncRoot
44 {
45 get
46 {
48 {
49 return this;
50 }
51 return collection.SyncRoot;
52 }
53 }
54
55 object? IList.this[int index]
56 {
57 get
58 {
59 return items[index];
60 }
61 set
62 {
63 ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
64 T value2 = default(T);
65 try
66 {
67 value2 = (T)value;
68 }
70 {
71 ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
72 }
73 this[index] = value2;
74 }
75 }
76
77 bool IList.IsReadOnly => items.IsReadOnly;
78
79 bool IList.IsFixedSize
80 {
81 get
82 {
83 if (items is IList list)
84 {
85 return list.IsFixedSize;
86 }
87 return items.IsReadOnly;
88 }
89 }
90
91 public Collection()
92 {
93 items = new List<T>();
94 }
95
97 {
98 if (list == null)
99 {
101 }
102 items = list;
103 }
104
105 public void Add(T item)
106 {
107 if (items.IsReadOnly)
108 {
109 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
110 }
111 int count = items.Count;
113 }
114
115 public void Clear()
116 {
117 if (items.IsReadOnly)
118 {
119 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
120 }
121 ClearItems();
122 }
123
124 public void CopyTo(T[] array, int index)
125 {
126 items.CopyTo(array, index);
127 }
128
129 public bool Contains(T item)
130 {
131 return items.Contains(item);
132 }
133
135 {
136 return items.GetEnumerator();
137 }
138
139 public int IndexOf(T item)
140 {
141 return items.IndexOf(item);
142 }
143
144 public void Insert(int index, T item)
145 {
146 if (items.IsReadOnly)
147 {
148 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
149 }
150 if ((uint)index > (uint)items.Count)
151 {
153 }
155 }
156
157 public bool Remove(T item)
158 {
159 if (items.IsReadOnly)
160 {
161 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
162 }
163 int num = items.IndexOf(item);
164 if (num < 0)
165 {
166 return false;
167 }
168 RemoveItem(num);
169 return true;
170 }
171
172 public void RemoveAt(int index)
173 {
174 if (items.IsReadOnly)
175 {
176 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
177 }
178 if ((uint)index >= (uint)items.Count)
179 {
181 }
183 }
184
185 protected virtual void ClearItems()
186 {
187 items.Clear();
188 }
189
190 protected virtual void InsertItem(int index, T item)
191 {
193 }
194
195 protected virtual void RemoveItem(int index)
196 {
198 }
199
200 protected virtual void SetItem(int index, T item)
201 {
202 items[index] = item;
203 }
204
206 {
207 return ((IEnumerable)items).GetEnumerator();
208 }
209
211 {
212 if (array == null)
213 {
215 }
216 if (array.Rank != 1)
217 {
218 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
219 }
220 if (array.GetLowerBound(0) != 0)
221 {
223 }
224 if (index < 0)
225 {
227 }
228 if (array.Length - index < Count)
229 {
230 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
231 }
232 if (array is T[] array2)
233 {
234 items.CopyTo(array2, index);
235 return;
236 }
237 Type elementType = array.GetType().GetElementType();
239 if (!elementType.IsAssignableFrom(typeFromHandle) && !typeFromHandle.IsAssignableFrom(elementType))
240 {
242 }
243 object[] array3 = array as object[];
244 if (array3 == null)
245 {
247 }
248 int count = items.Count;
249 try
250 {
251 for (int i = 0; i < count; i++)
252 {
253 array3[index++] = items[i];
254 }
255 }
257 {
259 }
260 }
261
262 int IList.Add(object value)
263 {
264 if (items.IsReadOnly)
265 {
266 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
267 }
268 ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
269 T item = default(T);
270 try
271 {
272 item = (T)value;
273 }
275 {
276 ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
277 }
278 Add(item);
279 return Count - 1;
280 }
281
282 bool IList.Contains(object value)
283 {
285 {
286 return Contains((T)value);
287 }
288 return false;
289 }
290
291 int IList.IndexOf(object value)
292 {
294 {
295 return IndexOf((T)value);
296 }
297 return -1;
298 }
299
300 void IList.Insert(int index, object value)
301 {
302 if (items.IsReadOnly)
303 {
304 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
305 }
306 ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
307 T item = default(T);
308 try
309 {
310 item = (T)value;
311 }
313 {
314 ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
315 }
316 Insert(index, item);
317 }
318
319 void IList.Remove(object value)
320 {
321 if (items.IsReadOnly)
322 {
323 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
324 }
326 {
327 Remove((T)value);
328 }
329 }
330
331 private static bool IsCompatibleObject(object value)
332 {
333 if (!(value is T))
334 {
335 if (value == null)
336 {
337 return default(T) == null;
338 }
339 return false;
340 }
341 return true;
342 }
343}
bool ICollection< KeyValuePair< TKey, TValue > >. IsReadOnly
virtual void InsertItem(int index, T item)
static bool IsCompatibleObject(object value)
void CopyTo(T[] array, int index)
virtual void SetItem(int index, T item)
static void ThrowNotSupportedException(ExceptionResource resource)
static void ThrowArgumentOutOfRange_IndexException()
static void ThrowArgumentException_Argument_InvalidArrayType()
static void ThrowArgumentNullException(string name)
static void ThrowArgumentException(ExceptionResource resource)
static void ThrowIndexArgumentOutOfRange_NeedNonNegNumException()
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
void CopyTo(Array array, int index)
void RemoveAt(int index)
void Insert(int index, object? value)
int Add(object? value)
bool Contains(object? value)
void Remove(object? value)
int IndexOf(object? value)