Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 28.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Diagnostics;
  4. using System.Runtime;
  5. using System.Runtime.Versioning;
  6. using System.Threading;
  7. namespace System.Collections.Generic
  8. {
  9.     [__DynamicallyInvokable, DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(typeof(Mscorlib_CollectionDebugView<>))]
  10.     [Serializable]
  11.     public class List<T> : IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
  12.     {
  13.         [Serializable]
  14.         internal class SynchronizedList : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
  15.         {
  16.             private List<T> _list;
  17.             private object _root;
  18.             public int Count
  19.             {
  20.                 get
  21.                 {
  22.                     int count;
  23.                     lock (this._root)
  24.                     {
  25.                         count = this._list.Count;
  26.                     }
  27.                     return count;
  28.                 }
  29.             }
  30.             public bool IsReadOnly
  31.             {
  32.                 get
  33.                 {
  34.                     return ((ICollection<T>)this._list).IsReadOnly;
  35.                 }
  36.             }
  37.             public T this[int index]
  38.             {
  39.                 get
  40.                 {
  41.                     T result;
  42.                     lock (this._root)
  43.                     {
  44.                         result = this._list[index];
  45.                     }
  46.                     return result;
  47.                 }
  48.                 set
  49.                 {
  50.                     lock (this._root)
  51.                     {
  52.                         this._list[index] = value;
  53.                     }
  54.                 }
  55.             }
  56.             internal SynchronizedList(List<T> list)
  57.             {
  58.                 this._list = list;
  59.                 this._root = ((ICollection)list).SyncRoot;
  60.             }
  61.             public void Add(T item)
  62.             {
  63.                 lock (this._root)
  64.                 {
  65.                     this._list.Add(item);
  66.                 }
  67.             }
  68.             public void Clear()
  69.             {
  70.                 lock (this._root)
  71.                 {
  72.                     this._list.Clear();
  73.                 }
  74.             }
  75.             public bool Contains(T item)
  76.             {
  77.                 bool result;
  78.                 lock (this._root)
  79.                 {
  80.                     result = this._list.Contains(item);
  81.                 }
  82.                 return result;
  83.             }
  84.             public void CopyTo(T[] array, int arrayIndex)
  85.             {
  86.                 lock (this._root)
  87.                 {
  88.                     this._list.CopyTo(array, arrayIndex);
  89.                 }
  90.             }
  91.             public bool Remove(T item)
  92.             {
  93.                 bool result;
  94.                 lock (this._root)
  95.                 {
  96.                     result = this._list.Remove(item);
  97.                 }
  98.                 return result;
  99.             }
  100.             IEnumerator IEnumerable.GetEnumerator()
  101.             {
  102.                 IEnumerator result;
  103.                 lock (this._root)
  104.                 {
  105.                     result = this._list.GetEnumerator();
  106.                 }
  107.                 return result;
  108.             }
  109.             IEnumerator<T> IEnumerable<T>.GetEnumerator()
  110.             {
  111.                 IEnumerator<T> enumerator;
  112.                 lock (this._root)
  113.                 {
  114.                     enumerator = ((IEnumerable<T>)this._list).GetEnumerator();
  115.                 }
  116.                 return enumerator;
  117.             }
  118.             public int IndexOf(T item)
  119.             {
  120.                 int result;
  121.                 lock (this._root)
  122.                 {
  123.                     result = this._list.IndexOf(item);
  124.                 }
  125.                 return result;
  126.             }
  127.             public void Insert(int index, T item)
  128.             {
  129.                 lock (this._root)
  130.                 {
  131.                     this._list.Insert(index, item);
  132.                 }
  133.             }
  134.             public void RemoveAt(int index)
  135.             {
  136.                 lock (this._root)
  137.                 {
  138.                     this._list.RemoveAt(index);
  139.                 }
  140.             }
  141.         }
  142.         [__DynamicallyInvokable]
  143.         [Serializable]
  144.         public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
  145.         {
  146.             private List<T> list;
  147.             private int index;
  148.             private int version;
  149.             private T current;
  150.             [__DynamicallyInvokable]
  151.             public T Current
  152.             {
  153.                 [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  154.                 get
  155.                 {
  156.                     return this.current;
  157.                 }
  158.             }
  159.             [__DynamicallyInvokable]
  160.             object IEnumerator.Current
  161.             {
  162.                 [__DynamicallyInvokable]
  163.                 get
  164.                 {
  165.                     if (this.index == 0 || this.index == this.list._size + 1)
  166.                     {
  167.                         ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
  168.                     }
  169.                     return this.Current;
  170.                 }
  171.             }
  172.             internal Enumerator(List<T> list)
  173.             {
  174.                 this.list = list;
  175.                 this.index = 0;
  176.                 this.version = list._version;
  177.                 this.current = default(T);
  178.             }
  179.             [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  180.             public void Dispose()
  181.             {
  182.             }
  183.             [__DynamicallyInvokable]
  184.             public bool MoveNext()
  185.             {
  186.                 List<T> list = this.list;
  187.                 if (this.version == list._version && this.index < list._size)
  188.                 {
  189.                     this.current = list._items[this.index];
  190.                     this.index++;
  191.                     return true;
  192.                 }
  193.                 return this.MoveNextRare();
  194.             }
  195.             private bool MoveNextRare()
  196.             {
  197.                 if (this.version != this.list._version)
  198.                 {
  199.                     ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
  200.                 }
  201.                 this.index = this.list._size + 1;
  202.                 this.current = default(T);
  203.                 return false;
  204.             }
  205.             [__DynamicallyInvokable]
  206.             void IEnumerator.Reset()
  207.             {
  208.                 if (this.version != this.list._version)
  209.                 {
  210.                     ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
  211.                 }
  212.                 this.index = 0;
  213.                 this.current = default(T);
  214.             }
  215.         }
  216.         private T[] _items;
  217.         private int _size;
  218.         private int _version;
  219.         [NonSerialized]
  220.         private object _syncRoot;
  221.         private static readonly T[] _emptyArray = new T[0];
  222.         private const int _defaultCapacity = 4;
  223.         [__DynamicallyInvokable]
  224.         public int Capacity
  225.         {
  226.             [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  227.             get
  228.             {
  229.                 return this._items.Length;
  230.             }
  231.             [__DynamicallyInvokable]
  232.             set
  233.             {
  234.                 if (value < this._size)
  235.                 {
  236.                     ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value, ExceptionResource.ArgumentOutOfRange_SmallCapacity);
  237.                 }
  238.                 if (value != this._items.Length)
  239.                 {
  240.                     if (value > 0)
  241.                     {
  242.                         T[] array = new T[value];
  243.                         if (this._size > 0)
  244.                         {
  245.                             Array.Copy(this._items, 0, array, 0, this._size);
  246.                         }
  247.                         this._items = array;
  248.                         return;
  249.                     }
  250.                     this._items = List<T>._emptyArray;
  251.                 }
  252.             }
  253.         }
  254.         [__DynamicallyInvokable]
  255.         public int Count
  256.         {
  257.             [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  258.             get
  259.             {
  260.                 return this._size;
  261.             }
  262.         }
  263.         [__DynamicallyInvokable]
  264.         bool IList.IsFixedSize
  265.         {
  266.             [__DynamicallyInvokable]
  267.             get
  268.             {
  269.                 return false;
  270.             }
  271.         }
  272.         [__DynamicallyInvokable]
  273.         bool ICollection<T>.IsReadOnly
  274.         {
  275.             [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  276.             get
  277.             {
  278.                 return false;
  279.             }
  280.         }
  281.         [__DynamicallyInvokable]
  282.         bool IList.IsReadOnly
  283.         {
  284.             [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  285.             get
  286.             {
  287.                 return false;
  288.             }
  289.         }
  290.         [__DynamicallyInvokable]
  291.         bool ICollection.IsSynchronized
  292.         {
  293.             [__DynamicallyInvokable]
  294.             get
  295.             {
  296.                 return false;
  297.             }
  298.         }
  299.         [__DynamicallyInvokable]
  300.         object ICollection.SyncRoot
  301.         {
  302.             [__DynamicallyInvokable]
  303.             get
  304.             {
  305.                 if (this._syncRoot == null)
  306.                 {
  307.                     Interlocked.CompareExchange<object>(ref this._syncRoot, new object(), null);
  308.                 }
  309.                 return this._syncRoot;
  310.             }
  311.         }
  312.         [__DynamicallyInvokable]
  313.         public T this[int index]
  314.         {
  315.             [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  316.             get
  317.             {
  318.                 if (index >= this._size)
  319.                 {
  320.                     ThrowHelper.ThrowArgumentOutOfRangeException();
  321.                 }
  322.                 return this._items[index];
  323.             }
  324.             [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  325.             set
  326.             {
  327.                 if (index >= this._size)
  328.                 {
  329.                     ThrowHelper.ThrowArgumentOutOfRangeException();
  330.                 }
  331.                 this._items[index] = value;
  332.                 this._version++;
  333.             }
  334.         }
  335.         [__DynamicallyInvokable]
  336.         object IList.this[int index]
  337.         {
  338.             [__DynamicallyInvokable]
  339.             get
  340.             {
  341.                 return this[index];
  342.             }
  343.             [__DynamicallyInvokable]
  344.             set
  345.             {
  346.                 ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
  347.                 try
  348.                 {
  349.                     this[index] = (T)((object)value);
  350.                 }
  351.                 catch (InvalidCastException)
  352.                 {
  353.                     ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
  354.                 }
  355.             }
  356.         }
  357.         [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  358.         public List()
  359.         {
  360.             this._items = List<T>._emptyArray;
  361.         }
  362.         [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  363.         public List(int capacity)
  364.         {
  365.             if (capacity < 0)
  366.             {
  367.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  368.             }
  369.             if (capacity == 0)
  370.             {
  371.                 this._items = List<T>._emptyArray;
  372.                 return;
  373.             }
  374.             this._items = new T[capacity];
  375.         }
  376.         [__DynamicallyInvokable]
  377.         public List(IEnumerable<T> collection)
  378.         {
  379.             if (collection == null)
  380.             {
  381.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
  382.             }
  383.             ICollection<T> collection2 = collection as ICollection<T>;
  384.             if (collection2 == null)
  385.             {
  386.                 this._size = 0;
  387.                 this._items = List<T>._emptyArray;
  388.                 using (IEnumerator<T> enumerator = collection.GetEnumerator())
  389.                 {
  390.                     while (enumerator.MoveNext())
  391.                     {
  392.                         this.Add(enumerator.Current);
  393.                     }
  394.                 }
  395.                 return;
  396.             }
  397.             int count = collection2.Count;
  398.             if (count == 0)
  399.             {
  400.                 this._items = List<T>._emptyArray;
  401.                 return;
  402.             }
  403.             this._items = new T[count];
  404.             collection2.CopyTo(this._items, 0);
  405.             this._size = count;
  406.         }
  407.         private static bool IsCompatibleObject(object value)
  408.         {
  409.             return value is T || (value == null && default(T) == null);
  410.         }
  411.         [__DynamicallyInvokable]
  412.         public void Add(T item)
  413.         {
  414.             if (this._size == this._items.Length)
  415.             {
  416.                 this.EnsureCapacity(this._size + 1);
  417.             }
  418.             this._items[this._size++] = item;
  419.             this._version++;
  420.         }
  421.         [__DynamicallyInvokable]
  422.         int IList.Add(object item)
  423.         {
  424.             ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(item, ExceptionArgument.item);
  425.             try
  426.             {
  427.                 this.Add((T)((object)item));
  428.             }
  429.             catch (InvalidCastException)
  430.             {
  431.                 ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
  432.             }
  433.             return this.Count - 1;
  434.         }
  435.         [__DynamicallyInvokable]
  436.         public void AddRange(IEnumerable<T> collection)
  437.         {
  438.             this.InsertRange(this._size, collection);
  439.         }
  440.         public ReadOnlyCollection<T> AsReadOnly()
  441.         {
  442.             return new ReadOnlyCollection<T>(this);
  443.         }
  444.         [__DynamicallyInvokable]
  445.         public int BinarySearch(int index, int count, T item, IComparer<T> comparer)
  446.         {
  447.             if (index < 0)
  448.             {
  449.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  450.             }
  451.             if (count < 0)
  452.             {
  453.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  454.             }
  455.             if (this._size - index < count)
  456.             {
  457.                 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
  458.             }
  459.             return Array.BinarySearch<T>(this._items, index, count, item, comparer);
  460.         }
  461.         [__DynamicallyInvokable]
  462.         public int BinarySearch(T item)
  463.         {
  464.             return this.BinarySearch(0, this.Count, item, null);
  465.         }
  466.         [__DynamicallyInvokable]
  467.         public int BinarySearch(T item, IComparer<T> comparer)
  468.         {
  469.             return this.BinarySearch(0, this.Count, item, comparer);
  470.         }
  471.         [__DynamicallyInvokable]
  472.         public void Clear()
  473.         {
  474.             if (this._size > 0)
  475.             {
  476.                 Array.Clear(this._items, 0, this._size);
  477.                 this._size = 0;
  478.             }
  479.             this._version++;
  480.         }
  481.         [__DynamicallyInvokable]
  482.         public bool Contains(T item)
  483.         {
  484.             if (item == null)
  485.             {
  486.                 for (int i = 0; i < this._size; i++)
  487.                 {
  488.                     if (this._items[i] == null)
  489.                     {
  490.                         return true;
  491.                     }
  492.                 }
  493.                 return false;
  494.             }
  495.             EqualityComparer<T> @default = EqualityComparer<T>.Default;
  496.             for (int j = 0; j < this._size; j++)
  497.             {
  498.                 if (@default.Equals(this._items[j], item))
  499.                 {
  500.                     return true;
  501.                 }
  502.             }
  503.             return false;
  504.         }
  505.         [__DynamicallyInvokable]
  506.         bool IList.Contains(object item)
  507.         {
  508.             return List<T>.IsCompatibleObject(item) && this.Contains((T)((object)item));
  509.         }
  510.         public List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter)
  511.         {
  512.             if (converter == null)
  513.             {
  514.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.converter);
  515.             }
  516.             List<TOutput> list = new List<TOutput>(this._size);
  517.             for (int i = 0; i < this._size; i++)
  518.             {
  519.                 list._items[i] = converter(this._items[i]);
  520.             }
  521.             list._size = this._size;
  522.             return list;
  523.         }
  524.         [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  525.         public void CopyTo(T[] array)
  526.         {
  527.             this.CopyTo(array, 0);
  528.         }
  529.         [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  530.         void ICollection.CopyTo(Array array, int arrayIndex)
  531.         {
  532.             if (array != null && array.Rank != 1)
  533.             {
  534.                 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
  535.             }
  536.             try
  537.             {
  538.                 Array.Copy(this._items, 0, array, arrayIndex, this._size);
  539.             }
  540.             catch (ArrayTypeMismatchException)
  541.             {
  542.                 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
  543.             }
  544.         }
  545.         [__DynamicallyInvokable]
  546.         public void CopyTo(int index, T[] array, int arrayIndex, int count)
  547.         {
  548.             if (this._size - index < count)
  549.             {
  550.                 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
  551.             }
  552.             Array.Copy(this._items, index, array, arrayIndex, count);
  553.         }
  554.         [__DynamicallyInvokable]
  555.         public void CopyTo(T[] array, int arrayIndex)
  556.         {
  557.             Array.Copy(this._items, 0, array, arrayIndex, this._size);
  558.         }
  559.         private void EnsureCapacity(int min)
  560.         {
  561.             if (this._items.Length < min)
  562.             {
  563.                 int num = (this._items.Length == 0) ? 4 : (this._items.Length * 2);
  564.                 if (num > 2146435071)
  565.                 {
  566.                     num = 2146435071;
  567.                 }
  568.                 if (num < min)
  569.                 {
  570.                     num = min;
  571.                 }
  572.                 this.Capacity = num;
  573.             }
  574.         }
  575.         [__DynamicallyInvokable]
  576.         public bool Exists(Predicate<T> match)
  577.         {
  578.             return this.FindIndex(match) != -1;
  579.         }
  580.         [__DynamicallyInvokable]
  581.         public T Find(Predicate<T> match)
  582.         {
  583.             if (match == null)
  584.             {
  585.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
  586.             }
  587.             for (int i = 0; i < this._size; i++)
  588.             {
  589.                 if (match(this._items[i]))
  590.                 {
  591.                     return this._items[i];
  592.                 }
  593.             }
  594.             return default(T);
  595.         }
  596.         [__DynamicallyInvokable]
  597.         public List<T> FindAll(Predicate<T> match)
  598.         {
  599.             if (match == null)
  600.             {
  601.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
  602.             }
  603.             List<T> list = new List<T>();
  604.             for (int i = 0; i < this._size; i++)
  605.             {
  606.                 if (match(this._items[i]))
  607.                 {
  608.                     list.Add(this._items[i]);
  609.                 }
  610.             }
  611.             return list;
  612.         }
  613.         [__DynamicallyInvokable]
  614.         public int FindIndex(Predicate<T> match)
  615.         {
  616.             return this.FindIndex(0, this._size, match);
  617.         }
  618.         [__DynamicallyInvokable]
  619.         public int FindIndex(int startIndex, Predicate<T> match)
  620.         {
  621.             return this.FindIndex(startIndex, this._size - startIndex, match);
  622.         }
  623.         [__DynamicallyInvokable]
  624.         public int FindIndex(int startIndex, int count, Predicate<T> match)
  625.         {
  626.             if (startIndex > this._size)
  627.             {
  628.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
  629.             }
  630.             if (count < 0 || startIndex > this._size - count)
  631.             {
  632.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
  633.             }
  634.             if (match == null)
  635.             {
  636.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
  637.             }
  638.             int num = startIndex + count;
  639.             for (int i = startIndex; i < num; i++)
  640.             {
  641.                 if (match(this._items[i]))
  642.                 {
  643.                     return i;
  644.                 }
  645.             }
  646.             return -1;
  647.         }
  648.         [__DynamicallyInvokable]
  649.         public T FindLast(Predicate<T> match)
  650.         {
  651.             if (match == null)
  652.             {
  653.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
  654.             }
  655.             for (int i = this._size - 1; i >= 0; i--)
  656.             {
  657.                 if (match(this._items[i]))
  658.                 {
  659.                     return this._items[i];
  660.                 }
  661.             }
  662.             return default(T);
  663.         }
  664.         [__DynamicallyInvokable]
  665.         public int FindLastIndex(Predicate<T> match)
  666.         {
  667.             return this.FindLastIndex(this._size - 1, this._size, match);
  668.         }
  669.         [__DynamicallyInvokable]
  670.         public int FindLastIndex(int startIndex, Predicate<T> match)
  671.         {
  672.             return this.FindLastIndex(startIndex, startIndex + 1, match);
  673.         }
  674.         [__DynamicallyInvokable]
  675.         public int FindLastIndex(int startIndex, int count, Predicate<T> match)
  676.         {
  677.             if (match == null)
  678.             {
  679.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
  680.             }
  681.             if (this._size == 0)
  682.             {
  683.                 if (startIndex != -1)
  684.                 {
  685.                     ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
  686.                 }
  687.             }
  688.             else
  689.             {
  690.                 if (startIndex >= this._size)
  691.                 {
  692.                     ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
  693.                 }
  694.             }
  695.             if (count < 0 || startIndex - count + 1 < 0)
  696.             {
  697.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
  698.             }
  699.             int num = startIndex - count;
  700.             for (int i = startIndex; i > num; i--)
  701.             {
  702.                 if (match(this._items[i]))
  703.                 {
  704.                     return i;
  705.                 }
  706.             }
  707.             return -1;
  708.         }
  709.         public void ForEach(Action<T> action)
  710.         {
  711.             if (action == null)
  712.             {
  713.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
  714.             }
  715.             int version = this._version;
  716.             int num = 0;
  717.             while (num < this._size && (version == this._version || !BinaryCompatibility.TargetsAtLeast_Desktop_V4_5))
  718.             {
  719.                 action(this._items[num]);
  720.                 num++;
  721.             }
  722.             if (version != this._version && BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
  723.             {
  724.                 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
  725.             }
  726.         }
  727.         [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  728.         public List<T>.Enumerator GetEnumerator()
  729.         {
  730.             return new List<T>.Enumerator(this);
  731.         }
  732.         [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  733.         IEnumerator<T> IEnumerable<T>.GetEnumerator()
  734.         {
  735.             return new List<T>.Enumerator(this);
  736.         }
  737.         [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  738.         IEnumerator IEnumerable.GetEnumerator()
  739.         {
  740.             return new List<T>.Enumerator(this);
  741.         }
  742.         [__DynamicallyInvokable]
  743.         public List<T> GetRange(int index, int count)
  744.         {
  745.             if (index < 0)
  746.             {
  747.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  748.             }
  749.             if (count < 0)
  750.             {
  751.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  752.             }
  753.             if (this._size - index < count)
  754.             {
  755.                 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
  756.             }
  757.             List<T> list = new List<T>(count);
  758.             Array.Copy(this._items, index, list._items, 0, count);
  759.             list._size = count;
  760.             return list;
  761.         }
  762.         [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  763.         public int IndexOf(T item)
  764.         {
  765.             return Array.IndexOf<T>(this._items, item, 0, this._size);
  766.         }
  767.         [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  768.         int IList.IndexOf(object item)
  769.         {
  770.             if (List<T>.IsCompatibleObject(item))
  771.             {
  772.                 return this.IndexOf((T)((object)item));
  773.             }
  774.             return -1;
  775.         }
  776.         [__DynamicallyInvokable]
  777.         public int IndexOf(T item, int index)
  778.         {
  779.             if (index > this._size)
  780.             {
  781.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
  782.             }
  783.             return Array.IndexOf<T>(this._items, item, index, this._size - index);
  784.         }
  785.         [__DynamicallyInvokable]
  786.         public int IndexOf(T item, int index, int count)
  787.         {
  788.             if (index > this._size)
  789.             {
  790.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
  791.             }
  792.             if (count < 0 || index > this._size - count)
  793.             {
  794.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
  795.             }
  796.             return Array.IndexOf<T>(this._items, item, index, count);
  797.         }
  798.         [__DynamicallyInvokable]
  799.         public void Insert(int index, T item)
  800.         {
  801.             if (index > this._size)
  802.             {
  803.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
  804.             }
  805.             if (this._size == this._items.Length)
  806.             {
  807.                 this.EnsureCapacity(this._size + 1);
  808.             }
  809.             if (index < this._size)
  810.             {
  811.                 Array.Copy(this._items, index, this._items, index + 1, this._size - index);
  812.             }
  813.             this._items[index] = item;
  814.             this._size++;
  815.             this._version++;
  816.         }
  817.         [__DynamicallyInvokable]
  818.         void IList.Insert(int index, object item)
  819.         {
  820.             ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(item, ExceptionArgument.item);
  821.             try
  822.             {
  823.                 this.Insert(index, (T)((object)item));
  824.             }
  825.             catch (InvalidCastException)
  826.             {
  827.                 ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
  828.             }
  829.         }
  830.         [__DynamicallyInvokable]
  831.         public void InsertRange(int index, IEnumerable<T> collection)
  832.         {
  833.             if (collection == null)
  834.             {
  835.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
  836.             }
  837.             if (index > this._size)
  838.             {
  839.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
  840.             }
  841.             ICollection<T> collection2 = collection as ICollection<T>;
  842.             if (collection2 != null)
  843.             {
  844.                 int count = collection2.Count;
  845.                 if (count > 0)
  846.                 {
  847.                     this.EnsureCapacity(this._size + count);
  848.                     if (index < this._size)
  849.                     {
  850.                         Array.Copy(this._items, index, this._items, index + count, this._size - index);
  851.                     }
  852.                     if (this == collection2)
  853.                     {
  854.                         Array.Copy(this._items, 0, this._items, index, index);
  855.                         Array.Copy(this._items, index + count, this._items, index * 2, this._size - index);
  856.                     }
  857.                     else
  858.                     {
  859.                         T[] array = new T[count];
  860.                         collection2.CopyTo(array, 0);
  861.                         array.CopyTo(this._items, index);
  862.                     }
  863.                     this._size += count;
  864.                 }
  865.             }
  866.             else
  867.             {
  868.                 using (IEnumerator<T> enumerator = collection.GetEnumerator())
  869.                 {
  870.                     while (enumerator.MoveNext())
  871.                     {
  872.                         this.Insert(index++, enumerator.Current);
  873.                     }
  874.                 }
  875.             }
  876.             this._version++;
  877.         }
  878.         [__DynamicallyInvokable]
  879.         public int LastIndexOf(T item)
  880.         {
  881.             if (this._size == 0)
  882.             {
  883.                 return -1;
  884.             }
  885.             return this.LastIndexOf(item, this._size - 1, this._size);
  886.         }
  887.         [__DynamicallyInvokable]
  888.         public int LastIndexOf(T item, int index)
  889.         {
  890.             if (index >= this._size)
  891.             {
  892.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
  893.             }
  894.             return this.LastIndexOf(item, index, index + 1);
  895.         }
  896.         [__DynamicallyInvokable]
  897.         public int LastIndexOf(T item, int index, int count)
  898.         {
  899.             if (this.Count != 0 && index < 0)
  900.             {
  901.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  902.             }
  903.             if (this.Count != 0 && count < 0)
  904.             {
  905.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  906.             }
  907.             if (this._size == 0)
  908.             {
  909.                 return -1;
  910.             }
  911.             if (index >= this._size)
  912.             {
  913.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_BiggerThanCollection);
  914.             }
  915.             if (count > index + 1)
  916.             {
  917.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_BiggerThanCollection);
  918.             }
  919.             return Array.LastIndexOf<T>(this._items, item, index, count);
  920.         }
  921.         [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  922.         public bool Remove(T item)
  923.         {
  924.             int num = this.IndexOf(item);
  925.             if (num >= 0)
  926.             {
  927.                 this.RemoveAt(num);
  928.                 return true;
  929.             }
  930.             return false;
  931.         }
  932.         [__DynamicallyInvokable]
  933.         void IList.Remove(object item)
  934.         {
  935.             if (List<T>.IsCompatibleObject(item))
  936.             {
  937.                 this.Remove((T)((object)item));
  938.             }
  939.         }
  940.         [__DynamicallyInvokable]
  941.         public int RemoveAll(Predicate<T> match)
  942.         {
  943.             if (match == null)
  944.             {
  945.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
  946.             }
  947.             int num = 0;
  948.             while (num < this._size && !match(this._items[num]))
  949.             {
  950.                 num++;
  951.             }
  952.             if (num >= this._size)
  953.             {
  954.                 return 0;
  955.             }
  956.             int i = num + 1;
  957.             while (i < this._size)
  958.             {
  959.                 while (i < this._size && match(this._items[i]))
  960.                 {
  961.                     i++;
  962.                 }
  963.                 if (i < this._size)
  964.                 {
  965.                     this._items[num++] = this._items[i++];
  966.                 }
  967.             }
  968.             Array.Clear(this._items, num, this._size - num);
  969.             int result = this._size - num;
  970.             this._size = num;
  971.             this._version++;
  972.             return result;
  973.         }
  974.         [__DynamicallyInvokable]
  975.         public void RemoveAt(int index)
  976.         {
  977.             if (index >= this._size)
  978.             {
  979.                 ThrowHelper.ThrowArgumentOutOfRangeException();
  980.             }
  981.             this._size--;
  982.             if (index < this._size)
  983.             {
  984.                 Array.Copy(this._items, index + 1, this._items, index, this._size - index);
  985.             }
  986.             this._items[this._size] = default(T);
  987.             this._version++;
  988.         }
  989.         [__DynamicallyInvokable]
  990.         public void RemoveRange(int index, int count)
  991.         {
  992.             if (index < 0)
  993.             {
  994.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  995.             }
  996.             if (count < 0)
  997.             {
  998.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  999.             }
  1000.             if (this._size - index < count)
  1001.             {
  1002.                 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
  1003.             }
  1004.             if (count > 0)
  1005.             {
  1006.                 this._size -= count;
  1007.                 if (index < this._size)
  1008.                 {
  1009.                     Array.Copy(this._items, index + count, this._items, index, this._size - index);
  1010.                 }
  1011.                 Array.Clear(this._items, this._size, count);
  1012.                 this._version++;
  1013.             }
  1014.         }
  1015.         [__DynamicallyInvokable]
  1016.         public void Reverse()
  1017.         {
  1018.             this.Reverse(0, this.Count);
  1019.         }
  1020.         [__DynamicallyInvokable]
  1021.         public void Reverse(int index, int count)
  1022.         {
  1023.             if (index < 0)
  1024.             {
  1025.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  1026.             }
  1027.             if (count < 0)
  1028.             {
  1029.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  1030.             }
  1031.             if (this._size - index < count)
  1032.             {
  1033.                 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
  1034.             }
  1035.             Array.Reverse(this._items, index, count);
  1036.             this._version++;
  1037.         }
  1038.         [__DynamicallyInvokable]
  1039.         public void Sort()
  1040.         {
  1041.             this.Sort(0, this.Count, null);
  1042.         }
  1043.         [__DynamicallyInvokable]
  1044.         public void Sort(IComparer<T> comparer)
  1045.         {
  1046.             this.Sort(0, this.Count, comparer);
  1047.         }
  1048.         [__DynamicallyInvokable]
  1049.         public void Sort(int index, int count, IComparer<T> comparer)
  1050.         {
  1051.             if (index < 0)
  1052.             {
  1053.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  1054.             }
  1055.             if (count < 0)
  1056.             {
  1057.                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
  1058.             }
  1059.             if (this._size - index < count)
  1060.             {
  1061.                 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
  1062.             }
  1063.             Array.Sort<T>(this._items, index, count, comparer);
  1064.             this._version++;
  1065.         }
  1066.         [__DynamicallyInvokable]
  1067.         public void Sort(Comparison<T> comparison)
  1068.         {
  1069.             if (comparison == null)
  1070.             {
  1071.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
  1072.             }
  1073.             if (this._size > 0)
  1074.             {
  1075.                 IComparer<T> comparer = new Array.FunctorComparer<T>(comparison);
  1076.                 Array.Sort<T>(this._items, 0, this._size, comparer);
  1077.             }
  1078.         }
  1079.         [__DynamicallyInvokable]
  1080.         public T[] ToArray()
  1081.         {
  1082.             T[] array = new T[this._size];
  1083.             Array.Copy(this._items, 0, array, 0, this._size);
  1084.             return array;
  1085.         }
  1086.         [__DynamicallyInvokable]
  1087.         public void TrimExcess()
  1088.         {
  1089.             int num = (int)((double)this._items.Length * 0.9);
  1090.             if (this._size < num)
  1091.             {
  1092.                 this.Capacity = this._size;
  1093.             }
  1094.         }
  1095.         [__DynamicallyInvokable]
  1096.         public bool TrueForAll(Predicate<T> match)
  1097.         {
  1098.             if (match == null)
  1099.             {
  1100.                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
  1101.             }
  1102.             for (int i = 0; i < this._size; i++)
  1103.             {
  1104.                 if (!match(this._items[i]))
  1105.                 {
  1106.                     return false;
  1107.                 }
  1108.             }
  1109.             return true;
  1110.         }
  1111.         internal static IList<T> Synchronized(List<T> list)
  1112.         {
  1113.             return new List<T>.SynchronizedList(list);
  1114.         }
  1115.     }
  1116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement