Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ListDictionaryInternal.cs
Go to the documentation of this file.
2
3namespace System.Collections;
4
6[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
8{
10 {
11 private readonly ListDictionaryInternal list;
12
14
15 private readonly int version;
16
17 private bool start;
18
19 public object Current => Entry;
20
22 {
23 get
24 {
25 if (current == null)
26 {
28 }
30 }
31 }
32
33 public object Key
34 {
35 get
36 {
37 if (current == null)
38 {
40 }
41 return current.key;
42 }
43 }
44
45 public object Value
46 {
47 get
48 {
49 if (current == null)
50 {
52 }
53 return current.value;
54 }
55 }
56
58 {
59 this.list = list;
61 start = true;
62 current = null;
63 }
64
65 public bool MoveNext()
66 {
67 if (version != list.version)
68 {
70 }
71 if (start)
72 {
74 start = false;
75 }
76 else if (current != null)
77 {
79 }
80 return current != null;
81 }
82
83 public void Reset()
84 {
85 if (version != list.version)
86 {
88 }
89 start = true;
90 current = null;
91 }
92 }
93
95 {
96 private sealed class NodeKeyValueEnumerator : IEnumerator
97 {
98 private readonly ListDictionaryInternal list;
99
101
102 private readonly int version;
103
104 private readonly bool isKeys;
105
106 private bool start;
107
108 public object Current
109 {
110 get
111 {
112 if (current == null)
113 {
115 }
116 if (!isKeys)
117 {
118 return current.value;
119 }
120 return current.key;
121 }
122 }
123
125 {
126 this.list = list;
127 this.isKeys = isKeys;
129 start = true;
130 current = null;
131 }
132
133 public bool MoveNext()
134 {
135 if (version != list.version)
136 {
138 }
139 if (start)
140 {
141 current = list.head;
142 start = false;
143 }
144 else if (current != null)
145 {
147 }
148 return current != null;
149 }
150
151 public void Reset()
152 {
153 if (version != list.version)
154 {
156 }
157 start = true;
158 current = null;
159 }
160 }
161
162 private readonly ListDictionaryInternal list;
163
164 private readonly bool isKeys;
165
166 int ICollection.Count
167 {
168 get
169 {
170 int num = 0;
171 for (DictionaryNode dictionaryNode = list.head; dictionaryNode != null; dictionaryNode = dictionaryNode.next)
172 {
173 num++;
174 }
175 return num;
176 }
177 }
178
179 bool ICollection.IsSynchronized => false;
180
181 object ICollection.SyncRoot => list.SyncRoot;
182
184 {
185 this.list = list;
186 this.isKeys = isKeys;
187 }
188
190 {
191 if (array == null)
192 {
193 throw new ArgumentNullException("array");
194 }
195 if (array.Rank != 1)
196 {
198 }
199 if (index < 0)
200 {
202 }
203 if (array.Length - index < list.Count)
204 {
206 }
207 for (DictionaryNode dictionaryNode = list.head; dictionaryNode != null; dictionaryNode = dictionaryNode.next)
208 {
209 array.SetValue(isKeys ? dictionaryNode.key : dictionaryNode.value, index);
210 index++;
211 }
212 }
213
218 }
219
220 [Serializable]
221 private sealed class DictionaryNode
222 {
223 public object key;
224
225 public object value;
226
228 }
229
231
232 private int version;
233
234 private int count;
235
236 public object? this[object key]
237 {
238 get
239 {
240 if (key == null)
241 {
242 throw new ArgumentNullException("key", SR.ArgumentNull_Key);
243 }
244 for (DictionaryNode next = head; next != null; next = next.next)
245 {
246 if (next.key.Equals(key))
247 {
248 return next.value;
249 }
250 }
251 return null;
252 }
253 set
254 {
255 if (key == null)
256 {
257 throw new ArgumentNullException("key", SR.ArgumentNull_Key);
258 }
259 version++;
260 DictionaryNode dictionaryNode = null;
261 DictionaryNode next = head;
262 while (next != null && !next.key.Equals(key))
263 {
264 dictionaryNode = next;
265 next = next.next;
266 }
267 if (next != null)
268 {
269 next.value = value;
270 return;
271 }
272 DictionaryNode dictionaryNode2 = new DictionaryNode();
273 dictionaryNode2.key = key;
274 dictionaryNode2.value = value;
275 if (dictionaryNode != null)
276 {
277 dictionaryNode.next = dictionaryNode2;
278 }
279 else
280 {
281 head = dictionaryNode2;
282 }
283 count++;
284 }
285 }
286
287 public int Count => count;
288
289 public ICollection Keys => new NodeKeyValueCollection(this, isKeys: true);
290
291 public bool IsReadOnly => false;
292
293 public bool IsFixedSize => false;
294
295 public bool IsSynchronized => false;
296
297 public object SyncRoot => this;
298
299 public ICollection Values => new NodeKeyValueCollection(this, isKeys: false);
300
301 public void Add(object key, object? value)
302 {
303 if (key == null)
304 {
305 throw new ArgumentNullException("key", SR.ArgumentNull_Key);
306 }
307 version++;
308 DictionaryNode dictionaryNode = null;
309 for (DictionaryNode next = head; next != null; next = next.next)
310 {
311 if (next.key.Equals(key))
312 {
314 }
315 dictionaryNode = next;
316 }
317 DictionaryNode dictionaryNode2 = new DictionaryNode();
318 dictionaryNode2.key = key;
319 dictionaryNode2.value = value;
320 if (dictionaryNode != null)
321 {
322 dictionaryNode.next = dictionaryNode2;
323 }
324 else
325 {
326 head = dictionaryNode2;
327 }
328 count++;
329 }
330
331 public void Clear()
332 {
333 count = 0;
334 head = null;
335 version++;
336 }
337
338 public bool Contains(object key)
339 {
340 if (key == null)
341 {
342 throw new ArgumentNullException("key", SR.ArgumentNull_Key);
343 }
344 for (DictionaryNode next = head; next != null; next = next.next)
345 {
346 if (next.key.Equals(key))
347 {
348 return true;
349 }
350 }
351 return false;
352 }
353
354 public void CopyTo(Array array, int index)
355 {
356 if (array == null)
357 {
358 throw new ArgumentNullException("array");
359 }
360 if (array.Rank != 1)
361 {
363 }
364 if (index < 0)
365 {
367 }
368 if (array.Length - index < Count)
369 {
371 }
372 for (DictionaryNode next = head; next != null; next = next.next)
373 {
374 array.SetValue(new DictionaryEntry(next.key, next.value), index);
375 index++;
376 }
377 }
378
380 {
381 return new NodeEnumerator(this);
382 }
383
385 {
386 return new NodeEnumerator(this);
387 }
388
389 public void Remove(object key)
390 {
391 if (key == null)
392 {
393 throw new ArgumentNullException("key", SR.ArgumentNull_Key);
394 }
395 version++;
396 DictionaryNode dictionaryNode = null;
397 DictionaryNode next = head;
398 while (next != null && !next.key.Equals(key))
399 {
400 dictionaryNode = next;
401 next = next.next;
402 }
403 if (next != null)
404 {
405 if (next == head)
406 {
407 head = next.next;
408 }
409 else
410 {
411 dictionaryNode.next = next.next;
412 }
413 count--;
414 }
415 }
416}
static string ArgumentOutOfRange_Index
Definition SR.cs:30
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Argument_AddingDuplicate__
Definition SR.cs:458
static string InvalidOperation_EnumFailedVersion
Definition SR.cs:44
static string Arg_RankMultiDimNotSupported
Definition SR.cs:18
static string ArgumentNull_Key
Definition SR.cs:28
static string InvalidOperation_EnumOpCantHappen
Definition SR.cs:48
static string ArgumentOutOfRange_NeedNonNegNum
Definition SR.cs:32
Definition SR.cs:7
void CopyTo(Array array, int index)