Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
List.cs
Go to the documentation of this file.
4
6
8[DebuggerTypeProxy(typeof(ICollectionDebugView<>))]
9[DebuggerDisplay("Count = {Count}")]
10[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
12{
14 {
15 private readonly List<T> _list;
16
17 private int _index;
18
19 private readonly int _version;
20
21 private T _current;
22
23 public T Current => _current;
24
25 object? IEnumerator.Current
26 {
27 get
28 {
29 if (_index == 0 || _index == _list._size + 1)
30 {
32 }
33 return Current;
34 }
35 }
36
38 {
39 _list = list;
40 _index = 0;
41 _version = list._version;
42 _current = default(T);
43 }
44
45 public void Dispose()
46 {
47 }
48
49 public bool MoveNext()
50 {
52 if (_version == list._version && (uint)_index < (uint)list._size)
53 {
54 _current = list._items[_index];
55 _index++;
56 return true;
57 }
58 return MoveNextRare();
59 }
60
61 private bool MoveNextRare()
62 {
63 if (_version != _list._version)
64 {
66 }
67 _index = _list._size + 1;
68 _current = default(T);
69 return false;
70 }
71
73 {
74 if (_version != _list._version)
75 {
77 }
78 _index = 0;
79 _current = default(T);
80 }
81 }
82
83 internal T[] _items;
84
85 internal int _size;
86
87 private int _version;
88
89 private static readonly T[] s_emptyArray = new T[0];
90
91 public int Capacity
92 {
93 get
94 {
95 return _items.Length;
96 }
97 set
98 {
99 if (value < _size)
100 {
102 }
103 if (value == _items.Length)
104 {
105 return;
106 }
107 if (value > 0)
108 {
109 T[] array = new T[value];
110 if (_size > 0)
111 {
113 }
114 _items = array;
115 }
116 else
117 {
119 }
120 }
121 }
122
123 public int Count => _size;
124
125 bool IList.IsFixedSize => false;
126
128
129 bool IList.IsReadOnly => false;
130
131 bool ICollection.IsSynchronized => false;
132
133 object ICollection.SyncRoot => this;
134
135 public T this[int index]
136 {
137 get
138 {
139 if ((uint)index >= (uint)_size)
140 {
142 }
143 return _items[index];
144 }
145 set
146 {
147 if ((uint)index >= (uint)_size)
148 {
150 }
151 _items[index] = value;
152 _version++;
153 }
154 }
155
156 object? IList.this[int index]
157 {
158 get
159 {
160 return this[index];
161 }
162 set
163 {
164 ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
165 try
166 {
167 this[index] = (T)value;
168 }
170 {
171 ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
172 }
173 }
174 }
175
176 public List()
177 {
179 }
180
181 public List(int capacity)
182 {
183 if (capacity < 0)
184 {
185 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
186 }
187 if (capacity == 0)
188 {
190 }
191 else
192 {
193 _items = new T[capacity];
194 }
195 }
196
198 {
199 if (collection == null)
200 {
202 }
204 {
205 if (count == 0)
206 {
208 return;
209 }
210 _items = new T[count];
212 _size = count;
213 return;
214 }
216 foreach (T item in collection)
217 {
218 Add(item);
219 }
220 }
221
222 private static bool IsCompatibleObject(object value)
223 {
224 if (!(value is T))
225 {
226 if (value == null)
227 {
228 return default(T) == null;
229 }
230 return false;
231 }
232 return true;
233 }
234
235 [MethodImpl(MethodImplOptions.AggressiveInlining)]
236 public void Add(T item)
237 {
238 _version++;
239 T[] items = _items;
240 int size = _size;
241 if ((uint)size < (uint)items.Length)
242 {
243 _size = size + 1;
244 items[size] = item;
245 }
246 else
247 {
249 }
250 }
251
252 [MethodImpl(MethodImplOptions.NoInlining)]
253 private void AddWithResize(T item)
254 {
255 int size = _size;
256 Grow(size + 1);
257 _size = size + 1;
258 _items[size] = item;
259 }
260
261 int IList.Add(object item)
262 {
263 ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(item, ExceptionArgument.item);
264 try
265 {
266 Add((T)item);
267 }
269 {
270 ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
271 }
272 return Count - 1;
273 }
274
279
281 {
282 return new ReadOnlyCollection<T>(this);
283 }
284
286 {
287 if (index < 0)
288 {
290 }
291 if (count < 0)
292 {
294 }
295 if (_size - index < count)
296 {
298 }
300 }
301
302 public int BinarySearch(T item)
303 {
304 return BinarySearch(0, Count, item, null);
305 }
306
308 {
309 return BinarySearch(0, Count, item, comparer);
310 }
311
312 [MethodImpl(MethodImplOptions.AggressiveInlining)]
313 public void Clear()
314 {
315 _version++;
316 if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
317 {
318 int size = _size;
319 _size = 0;
320 if (size > 0)
321 {
322 Array.Clear(_items, 0, size);
323 }
324 }
325 else
326 {
327 _size = 0;
328 }
329 }
330
331 public bool Contains(T item)
332 {
333 if (_size != 0)
334 {
335 return IndexOf(item) != -1;
336 }
337 return false;
338 }
339
340 bool IList.Contains(object item)
341 {
343 {
344 return Contains((T)item);
345 }
346 return false;
347 }
348
350 {
351 if (converter == null)
352 {
354 }
356 for (int i = 0; i < _size; i++)
357 {
358 list._items[i] = converter(_items[i]);
359 }
360 list._size = _size;
361 return list;
362 }
363
364 public void CopyTo(T[] array)
365 {
366 CopyTo(array, 0);
367 }
368
370 {
371 if (array != null && array.Rank != 1)
372 {
373 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
374 }
375 try
376 {
378 }
380 {
382 }
383 }
384
385 public void CopyTo(int index, T[] array, int arrayIndex, int count)
386 {
387 if (_size - index < count)
388 {
390 }
392 }
393
394 public void CopyTo(T[] array, int arrayIndex)
395 {
397 }
398
399 public int EnsureCapacity(int capacity)
400 {
401 if (capacity < 0)
402 {
403 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
404 }
405 if (_items.Length < capacity)
406 {
407 Grow(capacity);
408 _version++;
409 }
410 return _items.Length;
411 }
412
413 private void Grow(int capacity)
414 {
415 int num = ((_items.Length == 0) ? 4 : (2 * _items.Length));
416 if ((uint)num > Array.MaxLength)
417 {
418 num = Array.MaxLength;
419 }
420 if (num < capacity)
421 {
422 num = capacity;
423 }
424 Capacity = num;
425 }
426
428 {
429 return FindIndex(match) != -1;
430 }
431
433 {
434 if (match == null)
435 {
437 }
438 for (int i = 0; i < _size; i++)
439 {
440 if (match(_items[i]))
441 {
442 return _items[i];
443 }
444 }
445 return default(T);
446 }
447
449 {
450 if (match == null)
451 {
453 }
454 List<T> list = new List<T>();
455 for (int i = 0; i < _size; i++)
456 {
457 if (match(_items[i]))
458 {
459 list.Add(_items[i]);
460 }
461 }
462 return list;
463 }
464
466 {
467 return FindIndex(0, _size, match);
468 }
469
471 {
473 }
474
476 {
477 if ((uint)startIndex > (uint)_size)
478 {
480 }
482 {
484 }
485 if (match == null)
486 {
488 }
489 int num = startIndex + count;
490 for (int i = startIndex; i < num; i++)
491 {
492 if (match(_items[i]))
493 {
494 return i;
495 }
496 }
497 return -1;
498 }
499
501 {
502 if (match == null)
503 {
505 }
506 for (int num = _size - 1; num >= 0; num--)
507 {
508 if (match(_items[num]))
509 {
510 return _items[num];
511 }
512 }
513 return default(T);
514 }
515
517 {
518 return FindLastIndex(_size - 1, _size, match);
519 }
520
522 {
524 }
525
527 {
528 if (match == null)
529 {
531 }
532 if (_size == 0)
533 {
534 if (startIndex != -1)
535 {
537 }
538 }
539 else if ((uint)startIndex >= (uint)_size)
540 {
542 }
543 if (count < 0 || startIndex - count + 1 < 0)
544 {
546 }
547 int num = startIndex - count;
548 for (int num2 = startIndex; num2 > num; num2--)
549 {
550 if (match(_items[num2]))
551 {
552 return num2;
553 }
554 }
555 return -1;
556 }
557
559 {
560 if (action == null)
561 {
563 }
564 int version = _version;
565 for (int i = 0; i < _size; i++)
566 {
567 if (version != _version)
568 {
569 break;
570 }
571 action(_items[i]);
572 }
573 if (version != _version)
574 {
576 }
577 }
578
580 {
581 return new Enumerator(this);
582 }
583
585 {
586 return new Enumerator(this);
587 }
588
590 {
591 return new Enumerator(this);
592 }
593
594 public List<T> GetRange(int index, int count)
595 {
596 if (index < 0)
597 {
599 }
600 if (count < 0)
601 {
603 }
604 if (_size - index < count)
605 {
607 }
608 List<T> list = new List<T>(count);
609 Array.Copy(_items, index, list._items, 0, count);
610 list._size = count;
611 return list;
612 }
613
614 public int IndexOf(T item)
615 {
616 return Array.IndexOf(_items, item, 0, _size);
617 }
618
619 int IList.IndexOf(object item)
620 {
622 {
623 return IndexOf((T)item);
624 }
625 return -1;
626 }
627
628 public int IndexOf(T item, int index)
629 {
630 if (index > _size)
631 {
633 }
634 return Array.IndexOf(_items, item, index, _size - index);
635 }
636
649
650 public void Insert(int index, T item)
651 {
652 if ((uint)index > (uint)_size)
653 {
655 }
656 if (_size == _items.Length)
657 {
658 Grow(_size + 1);
659 }
660 if (index < _size)
661 {
663 }
664 _items[index] = item;
665 _size++;
666 _version++;
667 }
668
669 void IList.Insert(int index, object item)
670 {
671 ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(item, ExceptionArgument.item);
672 try
673 {
674 Insert(index, (T)item);
675 }
677 {
678 ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
679 }
680 }
681
683 {
684 if (collection == null)
685 {
687 }
688 if ((uint)index > (uint)_size)
689 {
691 }
693 {
694 if (count > 0)
695 {
696 if (_items.Length - _size < count)
697 {
698 Grow(_size + count);
699 }
700 if (index < _size)
701 {
703 }
704 if (this == collection2)
705 {
708 }
709 else
710 {
712 }
713 _size += count;
714 }
715 }
716 else
717 {
719 while (enumerator.MoveNext())
720 {
721 Insert(index++, enumerator.Current);
722 }
723 }
724 _version++;
725 }
726
727 public int LastIndexOf(T item)
728 {
729 if (_size == 0)
730 {
731 return -1;
732 }
733 return LastIndexOf(item, _size - 1, _size);
734 }
735
736 public int LastIndexOf(T item, int index)
737 {
738 if (index >= _size)
739 {
741 }
742 return LastIndexOf(item, index, index + 1);
743 }
744
745 public int LastIndexOf(T item, int index, int count)
746 {
747 if (Count != 0 && index < 0)
748 {
750 }
751 if (Count != 0 && count < 0)
752 {
754 }
755 if (_size == 0)
756 {
757 return -1;
758 }
759 if (index >= _size)
760 {
761 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_BiggerThanCollection);
762 }
763 if (count > index + 1)
764 {
765 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_BiggerThanCollection);
766 }
768 }
769
770 public bool Remove(T item)
771 {
772 int num = IndexOf(item);
773 if (num >= 0)
774 {
775 RemoveAt(num);
776 return true;
777 }
778 return false;
779 }
780
781 void IList.Remove(object item)
782 {
784 {
785 Remove((T)item);
786 }
787 }
788
790 {
791 if (match == null)
792 {
794 }
795 int i;
796 for (i = 0; i < _size && !match(_items[i]); i++)
797 {
798 }
799 if (i >= _size)
800 {
801 return 0;
802 }
803 int j = i + 1;
804 while (j < _size)
805 {
806 for (; j < _size && match(_items[j]); j++)
807 {
808 }
809 if (j < _size)
810 {
811 _items[i++] = _items[j++];
812 }
813 }
814 if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
815 {
816 Array.Clear(_items, i, _size - i);
817 }
818 int result = _size - i;
819 _size = i;
820 _version++;
821 return result;
822 }
823
824 public void RemoveAt(int index)
825 {
826 if ((uint)index >= (uint)_size)
827 {
829 }
830 _size--;
831 if (index < _size)
832 {
834 }
835 if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
836 {
837 _items[_size] = default(T);
838 }
839 _version++;
840 }
841
842 public void RemoveRange(int index, int count)
843 {
844 if (index < 0)
845 {
847 }
848 if (count < 0)
849 {
851 }
852 if (_size - index < count)
853 {
855 }
856 if (count > 0)
857 {
858 _size -= count;
859 if (index < _size)
860 {
862 }
863 _version++;
864 if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
865 {
867 }
868 }
869 }
870
871 public void Reverse()
872 {
873 Reverse(0, Count);
874 }
875
876 public void Reverse(int index, int count)
877 {
878 if (index < 0)
879 {
881 }
882 if (count < 0)
883 {
885 }
886 if (_size - index < count)
887 {
889 }
890 if (count > 1)
891 {
893 }
894 _version++;
895 }
896
897 public void Sort()
898 {
899 Sort(0, Count, null);
900 }
901
903 {
904 Sort(0, Count, comparer);
905 }
906
907 public void Sort(int index, int count, IComparer<T>? comparer)
908 {
909 if (index < 0)
910 {
912 }
913 if (count < 0)
914 {
916 }
917 if (_size - index < count)
918 {
920 }
921 if (count > 1)
922 {
924 }
925 _version++;
926 }
927
929 {
930 if (comparison == null)
931 {
933 }
934 if (_size > 1)
935 {
937 }
938 _version++;
939 }
940
941 public T[] ToArray()
942 {
943 if (_size == 0)
944 {
945 return s_emptyArray;
946 }
947 T[] array = new T[_size];
949 return array;
950 }
951
952 public void TrimExcess()
953 {
954 int num = (int)((double)_items.Length * 0.9);
955 if (_size < num)
956 {
957 Capacity = _size;
958 }
959 }
960
962 {
963 if (match == null)
964 {
966 }
967 for (int i = 0; i < _size; i++)
968 {
969 if (!match(_items[i]))
970 {
971 return false;
972 }
973 }
974 return true;
975 }
976}
static void Sort(Array array)
Definition Array.cs:2329
static void Reverse(Array array)
Definition Array.cs:2207
int IList. IndexOf(object value)
Definition Array.cs:1228
static int MaxLength
Definition Array.cs:471
static int LastIndexOf(Array array, object? value)
Definition Array.cs:1995
static unsafe void Clear(Array array)
Definition Array.cs:755
static int BinarySearch(Array array, object? value)
Definition Array.cs:1320
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
bool ICollection< KeyValuePair< TKey, TValue > >. IsReadOnly
List< T > FindAll(Predicate< T > match)
Definition List.cs:448
T? Find(Predicate< T > match)
Definition List.cs:432
int LastIndexOf(T item, int index)
Definition List.cs:736
void Sort(Comparison< T > comparison)
Definition List.cs:928
void Sort(int index, int count, IComparer< T >? comparer)
Definition List.cs:907
int FindLastIndex(int startIndex, int count, Predicate< T > match)
Definition List.cs:526
void CopyTo(T[] array, int arrayIndex)
Definition List.cs:394
ReadOnlyCollection< T > AsReadOnly()
Definition List.cs:280
void InsertRange(int index, IEnumerable< T > collection)
Definition List.cs:682
void Insert(int index, T item)
Definition List.cs:650
void Sort(IComparer< T >? comparer)
Definition List.cs:902
int IndexOf(T item, int index, int count)
Definition List.cs:637
void Reverse(int index, int count)
Definition List.cs:876
List< TOutput > ConvertAll< TOutput >(Converter< T, TOutput > converter)
Definition List.cs:349
T? FindLast(Predicate< T > match)
Definition List.cs:500
bool TrueForAll(Predicate< T > match)
Definition List.cs:961
List(IEnumerable< T > collection)
Definition List.cs:197
void AddRange(IEnumerable< T > collection)
Definition List.cs:275
void ForEach(Action< T > action)
Definition List.cs:558
int EnsureCapacity(int capacity)
Definition List.cs:399
int BinarySearch(T item, IComparer< T >? comparer)
Definition List.cs:307
int FindLastIndex(int startIndex, Predicate< T > match)
Definition List.cs:521
int FindLastIndex(Predicate< T > match)
Definition List.cs:516
void CopyTo(T[] array)
Definition List.cs:364
static readonly T[] s_emptyArray
Definition List.cs:89
void Grow(int capacity)
Definition List.cs:413
void RemoveAt(int index)
Definition List.cs:824
static bool IsCompatibleObject(object value)
Definition List.cs:222
bool Exists(Predicate< T > match)
Definition List.cs:427
int BinarySearch(int index, int count, T item, IComparer< T >? comparer)
Definition List.cs:285
int IndexOf(T item, int index)
Definition List.cs:628
void RemoveRange(int index, int count)
Definition List.cs:842
List< T > GetRange(int index, int count)
Definition List.cs:594
int FindIndex(int startIndex, int count, Predicate< T > match)
Definition List.cs:475
int LastIndexOf(T item, int index, int count)
Definition List.cs:745
int RemoveAll(Predicate< T > match)
Definition List.cs:789
int FindIndex(int startIndex, Predicate< T > match)
Definition List.cs:470
void CopyTo(int index, T[] array, int arrayIndex, int count)
Definition List.cs:385
int FindIndex(Predicate< T > match)
Definition List.cs:465
static void ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count()
static void ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen()
static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
static void ThrowArgumentOutOfRange_IndexException()
static void ThrowArgumentException_Argument_InvalidArrayType()
static void ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index()
static void ThrowArgumentNullException(string name)
static void ThrowArgumentException(ExceptionResource resource)
static void ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
static void ThrowIndexArgumentOutOfRange_NeedNonNegNumException()
void CopyTo(T[] array, int arrayIndex)
new IEnumerator< T > GetEnumerator()
void Insert(int index, T item)