Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PropertyDescriptorCollection.cs
Go to the documentation of this file.
3
5
7{
9 {
11
12 private int _index = -1;
13
14 public object Current => Entry;
15
24
25 public object Key => _owner[_index].Name;
26
27 public object Value => _owner[_index].Name;
28
33
34 public bool MoveNext()
35 {
36 if (_index < _owner.Count - 1)
37 {
38 _index++;
39 return true;
40 }
41 return false;
42 }
43
44 public void Reset()
45 {
46 _index = -1;
47 }
48 }
49
51
53
54 private bool _cachedIgnoreCase;
55
57
58 private readonly string[] _namedSort;
59
60 private readonly IComparer _comparer;
61
62 private bool _propsOwned;
63
64 private bool _needSort;
65
66 private readonly bool _readOnly;
67
68 private readonly object _internalSyncObject = new object();
69
70 public int Count { get; private set; }
71
72 public virtual PropertyDescriptor this[int index]
73 {
74 get
75 {
76 if (index >= Count)
77 {
78 throw new IndexOutOfRangeException();
79 }
81 return _properties[index];
82 }
83 }
84
85 public virtual PropertyDescriptor? this[string name] => Find(name, ignoreCase: false);
86
87 bool ICollection.IsSynchronized => false;
88
89 object ICollection.SyncRoot => null;
90
91 int ICollection.Count => Count;
92
93 bool IDictionary.IsFixedSize => _readOnly;
94
95 bool IDictionary.IsReadOnly => _readOnly;
96
97 object? IDictionary.this[object key]
98 {
99 get
100 {
101 if (key is string)
102 {
103 return this[(string)key];
104 }
105 return null;
106 }
107 set
108 {
109 if (_readOnly)
110 {
111 throw new NotSupportedException();
112 }
113 if (value != null && !(value is PropertyDescriptor))
114 {
115 throw new ArgumentException("value");
116 }
117 int num = -1;
118 if (key is int)
119 {
120 num = (int)key;
122 {
123 throw new IndexOutOfRangeException();
124 }
125 }
126 else
127 {
128 if (!(key is string))
129 {
130 throw new ArgumentException("key");
131 }
132 for (int i = 0; i < Count; i++)
133 {
134 if (_properties[i].Name.Equals((string)key))
135 {
136 num = i;
137 break;
138 }
139 }
140 }
141 if (num == -1)
142 {
144 return;
145 }
148 if (_cachedFoundProperties != null && key is string)
149 {
151 }
152 }
153 }
154
155 ICollection IDictionary.Keys
156 {
157 get
158 {
159 string[] array = new string[Count];
160 for (int i = 0; i < Count; i++)
161 {
162 array[i] = _properties[i].Name;
163 }
164 return array;
165 }
166 }
167
168 ICollection IDictionary.Values
169 {
170 get
171 {
172 if (_properties.Length != Count)
173 {
176 return array;
177 }
178 return (ICollection)_properties.Clone();
179 }
180 }
181
182 bool IList.IsReadOnly => _readOnly;
183
184 bool IList.IsFixedSize => _readOnly;
185
186 object? IList.this[int index]
187 {
188 get
189 {
190 return this[index];
191 }
192 set
193 {
194 if (_readOnly)
195 {
196 throw new NotSupportedException();
197 }
198 if (index >= Count)
199 {
200 throw new IndexOutOfRangeException();
201 }
202 if (value != null && !(value is PropertyDescriptor))
203 {
204 throw new ArgumentException("value");
205 }
208 }
209 }
210
212 {
213 if (properties == null)
214 {
216 Count = 0;
217 }
218 else
219 {
220 _properties = properties;
221 Count = properties.Length;
222 }
223 _propsOwned = true;
224 }
225
227 : this(properties)
228 {
230 }
231
233 {
234 _propsOwned = false;
235 if (namedSort != null)
236 {
237 _namedSort = (string[])namedSort.Clone();
238 }
240 _properties = properties;
242 _needSort = true;
243 }
244
246 {
247 if (_readOnly)
248 {
249 throw new NotSupportedException();
250 }
251 EnsureSize(Count + 1);
253 return Count - 1;
254 }
255
256 public void Clear()
257 {
258 if (_readOnly)
259 {
260 throw new NotSupportedException();
261 }
262 Count = 0;
264 }
265
267 {
268 return IndexOf(value) >= 0;
269 }
270
271 public void CopyTo(Array array, int index)
272 {
275 }
276
277 private void EnsurePropsOwned()
278 {
279 if (!_propsOwned)
280 {
281 _propsOwned = true;
282 if (_properties != null)
283 {
287 }
288 }
289 if (_needSort)
290 {
291 _needSort = false;
293 }
294 }
295
296 private void EnsureSize(int sizeNeeded)
297 {
298 if (sizeNeeded > _properties.Length)
299 {
300 if (_properties.Length == 0)
301 {
302 Count = 0;
304 return;
305 }
307 int num = Math.Max(sizeNeeded, _properties.Length * 2);
311 }
312 }
313
314 public virtual PropertyDescriptor? Find(string name, bool ignoreCase)
315 {
317 {
318 PropertyDescriptor result = null;
320 {
322 if (ignoreCase)
323 {
325 }
326 else
327 {
329 }
330 }
331 object obj = _cachedFoundProperties[name];
332 if (obj != null)
333 {
334 return (PropertyDescriptor)obj;
335 }
336 for (int i = 0; i < Count; i++)
337 {
338 if (ignoreCase)
339 {
340 if (string.Equals(_properties[i].Name, name, StringComparison.OrdinalIgnoreCase))
341 {
343 result = _properties[i];
344 break;
345 }
346 }
347 else if (_properties[i].Name.Equals(name))
348 {
350 result = _properties[i];
351 break;
352 }
353 }
354 return result;
355 }
356 }
357
362
364 {
365 if (_readOnly)
366 {
367 throw new NotSupportedException();
368 }
369 EnsureSize(Count + 1);
370 if (index < Count)
371 {
373 }
375 Count++;
376 }
377
379 {
380 if (_readOnly)
381 {
382 throw new NotSupportedException();
383 }
384 int num = IndexOf(value);
385 if (num != -1)
386 {
387 RemoveAt(num);
388 }
389 }
390
391 public void RemoveAt(int index)
392 {
393 if (_readOnly)
394 {
395 throw new NotSupportedException();
396 }
397 if (index < Count - 1)
398 {
400 }
401 _properties[Count - 1] = null;
402 Count--;
403 }
404
409
410 public virtual PropertyDescriptorCollection Sort(string[]? names)
411 {
413 }
414
419
424
425 protected void InternalSort(string[]? names)
426 {
427 if (_properties.Length == 0)
428 {
429 return;
430 }
432 if (names == null || names.Length == 0)
433 {
434 return;
435 }
437 int num = 0;
438 int num2 = _properties.Length;
439 for (int i = 0; i < names.Length; i++)
440 {
441 for (int j = 0; j < num2; j++)
442 {
444 if (propertyDescriptor != null && propertyDescriptor.Name.Equals(names[i]))
445 {
447 list[j] = null;
448 break;
449 }
450 }
451 }
452 for (int k = 0; k < num2; k++)
453 {
454 if (list[k] != null)
455 {
456 _properties[num++] = list[k];
457 }
458 }
459 }
460
462 {
463 if (sorter == null)
464 {
466 }
467 else
468 {
470 }
471 }
472
473 public virtual IEnumerator GetEnumerator()
474 {
476 if (_properties.Length != Count)
477 {
480 return array.GetEnumerator();
481 }
482 return _properties.GetEnumerator();
483 }
484
486 {
487 Clear();
488 }
489
491 {
492 Clear();
493 }
494
499
501 {
503 }
504
505 void IDictionary.Add(object key, object value)
506 {
508 {
509 throw new ArgumentException("value");
510 }
511 Add(value2);
512 }
513
515 {
516 if (key is string)
517 {
518 return this[(string)key] != null;
519 }
520 return false;
521 }
522
527
528 void IDictionary.Remove(object key)
529 {
530 if (key is string)
531 {
533 if (propertyDescriptor != null)
534 {
535 ((IList)this).Remove((object?)propertyDescriptor);
536 }
537 }
538 }
539
540 int IList.Add(object value)
541 {
543 }
544
545 bool IList.Contains(object value)
546 {
548 }
549
550 int IList.IndexOf(object value)
551 {
553 }
554
555 void IList.Insert(int index, object value)
556 {
558 }
559
560 void IList.Remove(object value)
561 {
563 }
564}
static void Sort(Array array)
Definition Array.cs:2329
int IList. IndexOf(object value)
Definition Array.cs:1228
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
PropertyDescriptorCollection(PropertyDescriptor[] properties, int propCount, string[] namedSort, IComparer comparer)
PropertyDescriptorCollection(PropertyDescriptor[]? properties, bool readOnly)
virtual PropertyDescriptorCollection Sort(IComparer? comparer)
virtual PropertyDescriptorCollection Sort(string[]? names, IComparer? comparer)
virtual ? PropertyDescriptor Find(string name, bool ignoreCase)
virtual PropertyDescriptorCollection Sort(string[]? names)
override bool Equals([NotNullWhen(true)] object? obj)
static void SortDescriptorArray(IList infos)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static StringComparer OrdinalIgnoreCase
void Add(TKey key, TValue value)
new IEnumerator< T > GetEnumerator()
void Insert(int index, T item)