Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
OrderedDictionary.cs
Go to the documentation of this file.
3
5
7[TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
9{
11 {
12 private readonly int _objectReturnType;
13
14 private readonly IEnumerator _arrayEnumerator;
15
16 public object Current
17 {
18 get
19 {
20 if (_objectReturnType == 1)
21 {
23 }
24 if (_objectReturnType == 2)
25 {
27 }
28 return Entry;
29 }
30 }
31
33
35
36 public object Value => ((DictionaryEntry)_arrayEnumerator.Current).Value;
37
43
44 public bool MoveNext()
45 {
47 }
48
49 public void Reset()
50 {
52 }
53 }
54
56 {
57 private readonly ArrayList _objects;
58
59 private readonly bool _isKeys;
60
62
64
66
68 {
70 _isKeys = isKeys;
71 }
72
74 {
75 if (array == null)
76 {
77 throw new ArgumentNullException("array");
78 }
79 if (index < 0)
80 {
82 }
83 foreach (object @object in _objects)
84 {
85 array.SetValue(_isKeys ? ((DictionaryEntry)@object).Key : ((DictionaryEntry)@object).Value, index);
86 index++;
87 }
88 }
89
94 }
95
97
99
100 private int _initialCapacity;
101
103
104 private bool _readOnly;
105
106 private readonly SerializationInfo _siInfo;
107
108 public int Count
109 {
110 get
111 {
112 if (_objectsArray == null)
113 {
114 return 0;
115 }
116 return _objectsArray.Count;
117 }
118 }
119
121
122 public bool IsReadOnly => _readOnly;
123
125
127 {
128 get
129 {
131 return new OrderedDictionaryKeyValueCollection(array, isKeys: true);
132 }
133 }
134
135 object ICollection.SyncRoot => this;
136
137 public object? this[int index]
138 {
139 get
140 {
142 return ((DictionaryEntry)arrayList[index]).Value;
143 }
144 set
145 {
146 if (_readOnly)
147 {
149 }
151 {
152 throw new ArgumentOutOfRangeException("index");
153 }
155 Hashtable hashtable = EnsureObjectsTable();
156 object key = ((DictionaryEntry)arrayList[index]).Key;
158 hashtable[key] = value;
159 }
160 }
161
162 public object? this[object key]
163 {
164 get
165 {
166 if (_objectsTable == null)
167 {
168 return null;
169 }
170 return _objectsTable[key];
171 }
172 set
173 {
174 if (_readOnly)
175 {
177 }
178 Hashtable hashtable = EnsureObjectsTable();
179 if (hashtable.Contains(key))
180 {
181 hashtable[key] = value;
184 }
185 else
186 {
187 Add(key, value);
188 }
189 }
190 }
191
193 {
194 get
195 {
197 return new OrderedDictionaryKeyValueCollection(array, isKeys: false);
198 }
199 }
200
202 : this(0)
203 {
204 }
205
207 : this(capacity, null)
208 {
209 }
210
215
221
223 {
224 _readOnly = true;
225 _objectsArray = dictionary._objectsArray;
226 _objectsTable = dictionary._objectsTable;
227 _comparer = dictionary._comparer;
228 _initialCapacity = dictionary._initialCapacity;
229 }
230
232 {
233 _siInfo = info;
234 }
235
240
245
246 public void Add(object key, object? value)
247 {
248 if (_readOnly)
249 {
251 }
252 Hashtable hashtable = EnsureObjectsTable();
254 hashtable.Add(key, value);
256 }
257
258 public void Clear()
259 {
260 if (_readOnly)
261 {
263 }
264 if (_objectsTable != null)
265 {
267 }
268 if (_objectsArray != null)
269 {
271 }
272 }
273
275 {
276 return new OrderedDictionary(this);
277 }
278
279 public bool Contains(object key)
280 {
281 if (key == null)
282 {
283 throw new ArgumentNullException("key");
284 }
285 if (_objectsTable == null)
286 {
287 return false;
288 }
289 return _objectsTable.Contains(key);
290 }
291
292 public void CopyTo(Array array, int index)
293 {
294 Hashtable hashtable = EnsureObjectsTable();
295 hashtable.CopyTo(array, index);
296 }
297
298 private int IndexOfKey(object key)
299 {
300 if (_objectsArray == null)
301 {
302 return -1;
303 }
304 for (int i = 0; i < _objectsArray.Count; i++)
305 {
306 object key2 = ((DictionaryEntry)_objectsArray[i]).Key;
307 if (_comparer != null)
308 {
309 if (_comparer.Equals(key2, key))
310 {
311 return i;
312 }
313 }
314 else if (key2.Equals(key))
315 {
316 return i;
317 }
318 }
319 return -1;
320 }
321
322 public void Insert(int index, object key, object? value)
323 {
324 if (_readOnly)
325 {
327 }
328 if (index > Count || index < 0)
329 {
330 throw new ArgumentOutOfRangeException("index");
331 }
332 Hashtable hashtable = EnsureObjectsTable();
334 hashtable.Add(key, value);
335 arrayList.Insert(index, new DictionaryEntry(key, value));
336 }
337
338 public void RemoveAt(int index)
339 {
340 if (_readOnly)
341 {
343 }
344 if (index >= Count || index < 0)
345 {
346 throw new ArgumentOutOfRangeException("index");
347 }
348 Hashtable hashtable = EnsureObjectsTable();
350 object key = ((DictionaryEntry)arrayList[index]).Key;
351 arrayList.RemoveAt(index);
352 hashtable.Remove(key);
353 }
354
355 public void Remove(object key)
356 {
357 if (_readOnly)
358 {
360 }
361 if (key == null)
362 {
363 throw new ArgumentNullException("key");
364 }
365 int num = IndexOfKey(key);
366 if (num >= 0)
367 {
368 Hashtable hashtable = EnsureObjectsTable();
370 hashtable.Remove(key);
371 arrayList.RemoveAt(num);
372 }
373 }
374
380
386
388 {
389 if (info == null)
390 {
391 throw new ArgumentNullException("info");
392 }
393 info.AddValue("KeyComparer", _comparer, typeof(IEqualityComparer));
394 info.AddValue("ReadOnly", _readOnly);
395 info.AddValue("InitialCapacity", _initialCapacity);
396 object[] array = new object[Count];
398 arrayList.CopyTo(array);
399 info.AddValue("ArrayList", array);
400 }
401
403 {
404 OnDeserialization(sender);
405 }
406
407 protected virtual void OnDeserialization(object? sender)
408 {
409 if (_siInfo == null)
410 {
412 }
414 _readOnly = _siInfo.GetBoolean("ReadOnly");
415 _initialCapacity = _siInfo.GetInt32("InitialCapacity");
416 object[] array = (object[])_siInfo.GetValue("ArrayList", typeof(object[]));
417 if (array == null)
418 {
419 return;
420 }
421 Hashtable hashtable = EnsureObjectsTable();
423 object[] array2 = array;
424 foreach (object obj in array2)
425 {
427 try
428 {
430 }
431 catch
432 {
434 }
436 hashtable.Add(dictionaryEntry.Key, dictionaryEntry.Value);
437 }
438 }
439}
virtual void CopyTo(Array array, int arrayIndex)
Definition Hashtable.cs:811
virtual bool Contains(object key)
Definition Hashtable.cs:719
virtual void Remove(object key)
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
OrderedDictionary(SerializationInfo info, StreamingContext context)
void IDeserializationCallback. OnDeserialization(object sender)
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
void Insert(int index, object key, object? value)
OrderedDictionary(int capacity, IEqualityComparer? comparer)
static string ArgumentOutOfRange_NeedNonNegNum_Index
Definition SR.cs:18
static string Serialization_InvalidOnDeser
Definition SR.cs:38
static string OrderedDictionary_SerializationMismatch
Definition SR.cs:36
static string OrderedDictionary_ReadOnly
Definition SR.cs:32
Definition SR.cs:7
void CopyTo(Array array, int index)
new bool Equals(object? x, object? y)