Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NameObjectCollectionBase.cs
Go to the documentation of this file.
4
6
8{
9 internal sealed class NameObjectEntry
10 {
11 internal string Key;
12
13 internal object Value;
14
15 internal NameObjectEntry(string name, object value)
16 {
17 Key = name;
18 Value = value;
19 }
20 }
21
22 internal sealed class NameObjectKeysEnumerator : IEnumerator
23 {
24 private int _pos;
25
27
28 private readonly int _version;
29
30 public object Current
31 {
32 get
33 {
34 if (_pos >= 0 && _pos < _coll.Count)
35 {
36 return _coll.BaseGetKey(_pos);
37 }
39 }
40 }
41
48
49 public bool MoveNext()
50 {
51 if (_version != _coll._version)
52 {
54 }
55 if (_pos < _coll.Count - 1)
56 {
57 _pos++;
58 return true;
59 }
61 return false;
62 }
63
64 public void Reset()
65 {
66 if (_version != _coll._version)
67 {
69 }
70 _pos = -1;
71 }
72 }
73
75 {
77
78 public string? this[int index] => Get(index);
79
80 public int Count => _coll.Count;
81
82 object ICollection.SyncRoot => ((ICollection)_coll).SyncRoot;
83
85
90
91 public virtual string? Get(int index)
92 {
93 return _coll.BaseGetKey(index);
94 }
95
97 {
99 }
100
102 {
103 if (array == null)
104 {
105 throw new ArgumentNullException("array");
106 }
107 if (array.Rank != 1)
108 {
109 throw new ArgumentException(System.SR.Arg_MultiRank, "array");
110 }
111 if (index < 0)
112 {
114 }
115 if (array.Length - index < _coll.Count)
116 {
118 }
120 while (enumerator.MoveNext())
121 {
122 array.SetValue(enumerator.Current, index++);
123 }
124 }
125 }
126
127 private bool _readOnly;
128
130
132
133 private volatile Hashtable _entriesTable;
134
136
138
139 private int _version;
140
141 private static readonly StringComparer s_defaultComparer = CultureInfo.InvariantCulture.CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
142
144 {
145 get
146 {
147 return _keyComparer;
148 }
149 set
150 {
152 }
153 }
154
155 protected bool IsReadOnly
156 {
157 get
158 {
159 return _readOnly;
160 }
161 set
162 {
164 }
165 }
166
167 public virtual int Count => _entriesArray.Count;
168
169 object ICollection.SyncRoot => this;
170
172
173 public virtual KeysCollection Keys
174 {
175 get
176 {
177 if (_keys == null)
178 {
179 _keys = new KeysCollection(this);
180 }
181 return _keys;
182 }
183 }
184
187 {
188 }
189
191 {
192 IEqualityComparer keyComparer;
193 if (equalityComparer != null)
194 {
195 keyComparer = equalityComparer;
196 }
197 else
198 {
200 keyComparer = equalityComparer2;
201 }
202 _keyComparer = keyComparer;
203 Reset();
204 }
205
211
212 [Obsolete("This constructor has been deprecated. Use NameObjectCollectionBase(IEqualityComparer) instead.")]
218
219 [Obsolete("This constructor has been deprecated. Use NameObjectCollectionBase(Int32, IEqualityComparer) instead.")]
225
231
236
238 {
240 }
241
242 public virtual void OnDeserialization(object? sender)
243 {
245 }
246
247 [MemberNotNull("_entriesArray")]
248 [MemberNotNull("_entriesTable")]
249 private void Reset()
250 {
251 _entriesArray = new ArrayList();
253 _nullKeyEntry = null;
254 _version++;
255 }
256
257 [MemberNotNull("_entriesArray")]
258 [MemberNotNull("_entriesTable")]
259 private void Reset(int capacity)
260 {
263 _nullKeyEntry = null;
264 _version++;
265 }
266
268 {
269 if (key != null)
270 {
272 }
273 return _nullKeyEntry;
274 }
275
276 protected bool BaseHasKeys()
277 {
278 return _entriesTable.Count > 0;
279 }
280
281 protected void BaseAdd(string? name, object? value)
282 {
283 if (_readOnly)
284 {
286 }
288 if (name != null)
289 {
290 if (_entriesTable[name] == null)
291 {
293 }
294 }
295 else if (_nullKeyEntry == null)
296 {
298 }
300 _version++;
301 }
302
303 protected void BaseRemove(string? name)
304 {
305 if (_readOnly)
306 {
308 }
309 if (name != null)
310 {
311 _entriesTable.Remove(name);
312 for (int num = _entriesArray.Count - 1; num >= 0; num--)
313 {
314 if (_keyComparer.Equals(name, BaseGetKey(num)))
315 {
317 }
318 }
319 }
320 else
321 {
322 _nullKeyEntry = null;
323 for (int num2 = _entriesArray.Count - 1; num2 >= 0; num2--)
324 {
325 if (BaseGetKey(num2) == null)
326 {
328 }
329 }
330 }
331 _version++;
332 }
333
334 protected void BaseRemoveAt(int index)
335 {
336 if (_readOnly)
337 {
339 }
340 string text = BaseGetKey(index);
341 if (text != null)
342 {
344 }
345 else
346 {
347 _nullKeyEntry = null;
348 }
350 _version++;
351 }
352
353 protected void BaseClear()
354 {
355 if (_readOnly)
356 {
358 }
359 Reset();
360 }
361
362 protected object? BaseGet(string? name)
363 {
364 return FindEntry(name)?.Value;
365 }
366
367 protected void BaseSet(string? name, object? value)
368 {
369 if (_readOnly)
370 {
372 }
374 if (nameObjectEntry != null)
375 {
377 _version++;
378 }
379 else
380 {
381 BaseAdd(name, value);
382 }
383 }
384
385 protected object? BaseGet(int index)
386 {
388 return nameObjectEntry.Value;
389 }
390
391 protected string? BaseGetKey(int index)
392 {
394 return nameObjectEntry.Key;
395 }
396
397 protected void BaseSet(int index, object? value)
398 {
399 if (_readOnly)
400 {
402 }
405 _version++;
406 }
407
408 public virtual IEnumerator GetEnumerator()
409 {
410 return new NameObjectKeysEnumerator(this);
411 }
412
414 {
415 if (array == null)
416 {
417 throw new ArgumentNullException("array");
418 }
419 if (array.Rank != 1)
420 {
421 throw new ArgumentException(System.SR.Arg_MultiRank, "array");
422 }
423 if (index < 0)
424 {
426 }
427 if (array.Length - index < _entriesArray.Count)
428 {
430 }
432 while (enumerator.MoveNext())
433 {
434 array.SetValue(enumerator.Current, index++);
435 }
436 }
437
438 protected string?[] BaseGetAllKeys()
439 {
441 string[] array = new string[count];
442 for (int i = 0; i < count; i++)
443 {
444 array[i] = BaseGetKey(i);
445 }
446 return array;
447 }
448
449 protected object?[] BaseGetAllValues()
450 {
452 object[] array = new object[count];
453 for (int i = 0; i < count; i++)
454 {
455 array[i] = BaseGet(i);
456 }
457 return array;
458 }
459
460 protected object?[] BaseGetAllValues(Type type)
461 {
463 if (type == null)
464 {
465 throw new ArgumentNullException("type");
466 }
467 object[] array = (object[])Array.CreateInstance(type, count);
468 for (int i = 0; i < count; i++)
469 {
470 array[i] = BaseGet(i);
471 }
472 return array;
473 }
474}
static unsafe Array CreateInstance(Type elementType, int length)
Definition Array.cs:473
virtual int Add(object? value)
virtual void RemoveAt(int index)
virtual void Remove(object key)
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
NameObjectCollectionBase(int capacity, IEqualityComparer? equalityComparer)
NameObjectCollectionBase(IHashCodeProvider? hashProvider, IComparer? comparer)
NameObjectCollectionBase(SerializationInfo info, StreamingContext context)
NameObjectCollectionBase(int capacity, IHashCodeProvider? hashProvider, IComparer? comparer)
static CultureInfo InvariantCulture
static string CollectionReadOnly
Definition SR.cs:28
static string Arg_MultiRank
Definition SR.cs:24
static string ArgumentOutOfRange_NeedNonNegNum_Index
Definition SR.cs:18
static string InvalidOperation_EnumFailedVersion
Definition SR.cs:44
static string InvalidOperation_EnumOpCantHappen
Definition SR.cs:48
static string Arg_InsufficientSpace
Definition SR.cs:26
Definition SR.cs:7
void CopyTo(Array array, int index)
new bool Equals(object? x, object? y)