Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.Runtime;
- using System.Runtime.Versioning;
- using System.Threading;
- namespace System.Collections.Generic
- {
- [__DynamicallyInvokable, DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(typeof(Mscorlib_CollectionDebugView<>))]
- [Serializable]
- public class List<T> : IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
- {
- [Serializable]
- internal class SynchronizedList : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
- {
- private List<T> _list;
- private object _root;
- public int Count
- {
- get
- {
- int count;
- lock (this._root)
- {
- count = this._list.Count;
- }
- return count;
- }
- }
- public bool IsReadOnly
- {
- get
- {
- return ((ICollection<T>)this._list).IsReadOnly;
- }
- }
- public T this[int index]
- {
- get
- {
- T result;
- lock (this._root)
- {
- result = this._list[index];
- }
- return result;
- }
- set
- {
- lock (this._root)
- {
- this._list[index] = value;
- }
- }
- }
- internal SynchronizedList(List<T> list)
- {
- this._list = list;
- this._root = ((ICollection)list).SyncRoot;
- }
- public void Add(T item)
- {
- lock (this._root)
- {
- this._list.Add(item);
- }
- }
- public void Clear()
- {
- lock (this._root)
- {
- this._list.Clear();
- }
- }
- public bool Contains(T item)
- {
- bool result;
- lock (this._root)
- {
- result = this._list.Contains(item);
- }
- return result;
- }
- public void CopyTo(T[] array, int arrayIndex)
- {
- lock (this._root)
- {
- this._list.CopyTo(array, arrayIndex);
- }
- }
- public bool Remove(T item)
- {
- bool result;
- lock (this._root)
- {
- result = this._list.Remove(item);
- }
- return result;
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- IEnumerator result;
- lock (this._root)
- {
- result = this._list.GetEnumerator();
- }
- return result;
- }
- IEnumerator<T> IEnumerable<T>.GetEnumerator()
- {
- IEnumerator<T> enumerator;
- lock (this._root)
- {
- enumerator = ((IEnumerable<T>)this._list).GetEnumerator();
- }
- return enumerator;
- }
- public int IndexOf(T item)
- {
- int result;
- lock (this._root)
- {
- result = this._list.IndexOf(item);
- }
- return result;
- }
- public void Insert(int index, T item)
- {
- lock (this._root)
- {
- this._list.Insert(index, item);
- }
- }
- public void RemoveAt(int index)
- {
- lock (this._root)
- {
- this._list.RemoveAt(index);
- }
- }
- }
- [__DynamicallyInvokable]
- [Serializable]
- public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
- {
- private List<T> list;
- private int index;
- private int version;
- private T current;
- [__DynamicallyInvokable]
- public T Current
- {
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.current;
- }
- }
- [__DynamicallyInvokable]
- object IEnumerator.Current
- {
- [__DynamicallyInvokable]
- get
- {
- if (this.index == 0 || this.index == this.list._size + 1)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
- }
- return this.Current;
- }
- }
- internal Enumerator(List<T> list)
- {
- this.list = list;
- this.index = 0;
- this.version = list._version;
- this.current = default(T);
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- public void Dispose()
- {
- }
- [__DynamicallyInvokable]
- public bool MoveNext()
- {
- List<T> list = this.list;
- if (this.version == list._version && this.index < list._size)
- {
- this.current = list._items[this.index];
- this.index++;
- return true;
- }
- return this.MoveNextRare();
- }
- private bool MoveNextRare()
- {
- if (this.version != this.list._version)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
- }
- this.index = this.list._size + 1;
- this.current = default(T);
- return false;
- }
- [__DynamicallyInvokable]
- void IEnumerator.Reset()
- {
- if (this.version != this.list._version)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
- }
- this.index = 0;
- this.current = default(T);
- }
- }
- private T[] _items;
- private int _size;
- private int _version;
- [NonSerialized]
- private object _syncRoot;
- private static readonly T[] _emptyArray = new T[0];
- private const int _defaultCapacity = 4;
- [__DynamicallyInvokable]
- public int Capacity
- {
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- get
- {
- return this._items.Length;
- }
- [__DynamicallyInvokable]
- set
- {
- if (value < this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value, ExceptionResource.ArgumentOutOfRange_SmallCapacity);
- }
- if (value != this._items.Length)
- {
- if (value > 0)
- {
- T[] array = new T[value];
- if (this._size > 0)
- {
- Array.Copy(this._items, 0, array, 0, this._size);
- }
- this._items = array;
- return;
- }
- this._items = List<T>._emptyArray;
- }
- }
- }
- [__DynamicallyInvokable]
- public int Count
- {
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this._size;
- }
- }
- [__DynamicallyInvokable]
- bool IList.IsFixedSize
- {
- [__DynamicallyInvokable]
- get
- {
- return false;
- }
- }
- [__DynamicallyInvokable]
- bool ICollection<T>.IsReadOnly
- {
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- get
- {
- return false;
- }
- }
- [__DynamicallyInvokable]
- bool IList.IsReadOnly
- {
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- get
- {
- return false;
- }
- }
- [__DynamicallyInvokable]
- bool ICollection.IsSynchronized
- {
- [__DynamicallyInvokable]
- get
- {
- return false;
- }
- }
- [__DynamicallyInvokable]
- object ICollection.SyncRoot
- {
- [__DynamicallyInvokable]
- get
- {
- if (this._syncRoot == null)
- {
- Interlocked.CompareExchange<object>(ref this._syncRoot, new object(), null);
- }
- return this._syncRoot;
- }
- }
- [__DynamicallyInvokable]
- public T this[int index]
- {
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- get
- {
- if (index >= this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException();
- }
- return this._items[index];
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- set
- {
- if (index >= this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException();
- }
- this._items[index] = value;
- this._version++;
- }
- }
- [__DynamicallyInvokable]
- object IList.this[int index]
- {
- [__DynamicallyInvokable]
- get
- {
- return this[index];
- }
- [__DynamicallyInvokable]
- set
- {
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
- try
- {
- this[index] = (T)((object)value);
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
- }
- }
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- public List()
- {
- this._items = List<T>._emptyArray;
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- public List(int capacity)
- {
- if (capacity < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (capacity == 0)
- {
- this._items = List<T>._emptyArray;
- return;
- }
- this._items = new T[capacity];
- }
- [__DynamicallyInvokable]
- public List(IEnumerable<T> collection)
- {
- if (collection == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
- }
- ICollection<T> collection2 = collection as ICollection<T>;
- if (collection2 == null)
- {
- this._size = 0;
- this._items = List<T>._emptyArray;
- using (IEnumerator<T> enumerator = collection.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- this.Add(enumerator.Current);
- }
- }
- return;
- }
- int count = collection2.Count;
- if (count == 0)
- {
- this._items = List<T>._emptyArray;
- return;
- }
- this._items = new T[count];
- collection2.CopyTo(this._items, 0);
- this._size = count;
- }
- private static bool IsCompatibleObject(object value)
- {
- return value is T || (value == null && default(T) == null);
- }
- [__DynamicallyInvokable]
- public void Add(T item)
- {
- if (this._size == this._items.Length)
- {
- this.EnsureCapacity(this._size + 1);
- }
- this._items[this._size++] = item;
- this._version++;
- }
- [__DynamicallyInvokable]
- int IList.Add(object item)
- {
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(item, ExceptionArgument.item);
- try
- {
- this.Add((T)((object)item));
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
- }
- return this.Count - 1;
- }
- [__DynamicallyInvokable]
- public void AddRange(IEnumerable<T> collection)
- {
- this.InsertRange(this._size, collection);
- }
- public ReadOnlyCollection<T> AsReadOnly()
- {
- return new ReadOnlyCollection<T>(this);
- }
- [__DynamicallyInvokable]
- public int BinarySearch(int index, int count, T item, IComparer<T> comparer)
- {
- if (index < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (this._size - index < count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- }
- return Array.BinarySearch<T>(this._items, index, count, item, comparer);
- }
- [__DynamicallyInvokable]
- public int BinarySearch(T item)
- {
- return this.BinarySearch(0, this.Count, item, null);
- }
- [__DynamicallyInvokable]
- public int BinarySearch(T item, IComparer<T> comparer)
- {
- return this.BinarySearch(0, this.Count, item, comparer);
- }
- [__DynamicallyInvokable]
- public void Clear()
- {
- if (this._size > 0)
- {
- Array.Clear(this._items, 0, this._size);
- this._size = 0;
- }
- this._version++;
- }
- [__DynamicallyInvokable]
- public bool Contains(T item)
- {
- if (item == null)
- {
- for (int i = 0; i < this._size; i++)
- {
- if (this._items[i] == null)
- {
- return true;
- }
- }
- return false;
- }
- EqualityComparer<T> @default = EqualityComparer<T>.Default;
- for (int j = 0; j < this._size; j++)
- {
- if (@default.Equals(this._items[j], item))
- {
- return true;
- }
- }
- return false;
- }
- [__DynamicallyInvokable]
- bool IList.Contains(object item)
- {
- return List<T>.IsCompatibleObject(item) && this.Contains((T)((object)item));
- }
- public List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter)
- {
- if (converter == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.converter);
- }
- List<TOutput> list = new List<TOutput>(this._size);
- for (int i = 0; i < this._size; i++)
- {
- list._items[i] = converter(this._items[i]);
- }
- list._size = this._size;
- return list;
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- public void CopyTo(T[] array)
- {
- this.CopyTo(array, 0);
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- void ICollection.CopyTo(Array array, int arrayIndex)
- {
- if (array != null && array.Rank != 1)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
- }
- try
- {
- Array.Copy(this._items, 0, array, arrayIndex, this._size);
- }
- catch (ArrayTypeMismatchException)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
- }
- }
- [__DynamicallyInvokable]
- public void CopyTo(int index, T[] array, int arrayIndex, int count)
- {
- if (this._size - index < count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- }
- Array.Copy(this._items, index, array, arrayIndex, count);
- }
- [__DynamicallyInvokable]
- public void CopyTo(T[] array, int arrayIndex)
- {
- Array.Copy(this._items, 0, array, arrayIndex, this._size);
- }
- private void EnsureCapacity(int min)
- {
- if (this._items.Length < min)
- {
- int num = (this._items.Length == 0) ? 4 : (this._items.Length * 2);
- if (num > 2146435071)
- {
- num = 2146435071;
- }
- if (num < min)
- {
- num = min;
- }
- this.Capacity = num;
- }
- }
- [__DynamicallyInvokable]
- public bool Exists(Predicate<T> match)
- {
- return this.FindIndex(match) != -1;
- }
- [__DynamicallyInvokable]
- public T Find(Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
- for (int i = 0; i < this._size; i++)
- {
- if (match(this._items[i]))
- {
- return this._items[i];
- }
- }
- return default(T);
- }
- [__DynamicallyInvokable]
- public List<T> FindAll(Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
- List<T> list = new List<T>();
- for (int i = 0; i < this._size; i++)
- {
- if (match(this._items[i]))
- {
- list.Add(this._items[i]);
- }
- }
- return list;
- }
- [__DynamicallyInvokable]
- public int FindIndex(Predicate<T> match)
- {
- return this.FindIndex(0, this._size, match);
- }
- [__DynamicallyInvokable]
- public int FindIndex(int startIndex, Predicate<T> match)
- {
- return this.FindIndex(startIndex, this._size - startIndex, match);
- }
- [__DynamicallyInvokable]
- public int FindIndex(int startIndex, int count, Predicate<T> match)
- {
- if (startIndex > this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
- }
- if (count < 0 || startIndex > this._size - count)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
- }
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
- int num = startIndex + count;
- for (int i = startIndex; i < num; i++)
- {
- if (match(this._items[i]))
- {
- return i;
- }
- }
- return -1;
- }
- [__DynamicallyInvokable]
- public T FindLast(Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
- for (int i = this._size - 1; i >= 0; i--)
- {
- if (match(this._items[i]))
- {
- return this._items[i];
- }
- }
- return default(T);
- }
- [__DynamicallyInvokable]
- public int FindLastIndex(Predicate<T> match)
- {
- return this.FindLastIndex(this._size - 1, this._size, match);
- }
- [__DynamicallyInvokable]
- public int FindLastIndex(int startIndex, Predicate<T> match)
- {
- return this.FindLastIndex(startIndex, startIndex + 1, match);
- }
- [__DynamicallyInvokable]
- public int FindLastIndex(int startIndex, int count, Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
- if (this._size == 0)
- {
- if (startIndex != -1)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
- }
- }
- else
- {
- if (startIndex >= this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
- }
- }
- if (count < 0 || startIndex - count + 1 < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
- }
- int num = startIndex - count;
- for (int i = startIndex; i > num; i--)
- {
- if (match(this._items[i]))
- {
- return i;
- }
- }
- return -1;
- }
- public void ForEach(Action<T> action)
- {
- if (action == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
- int version = this._version;
- int num = 0;
- while (num < this._size && (version == this._version || !BinaryCompatibility.TargetsAtLeast_Desktop_V4_5))
- {
- action(this._items[num]);
- num++;
- }
- if (version != this._version && BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
- }
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- public List<T>.Enumerator GetEnumerator()
- {
- return new List<T>.Enumerator(this);
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- IEnumerator<T> IEnumerable<T>.GetEnumerator()
- {
- return new List<T>.Enumerator(this);
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- IEnumerator IEnumerable.GetEnumerator()
- {
- return new List<T>.Enumerator(this);
- }
- [__DynamicallyInvokable]
- public List<T> GetRange(int index, int count)
- {
- if (index < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (this._size - index < count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- }
- List<T> list = new List<T>(count);
- Array.Copy(this._items, index, list._items, 0, count);
- list._size = count;
- return list;
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- public int IndexOf(T item)
- {
- return Array.IndexOf<T>(this._items, item, 0, this._size);
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- int IList.IndexOf(object item)
- {
- if (List<T>.IsCompatibleObject(item))
- {
- return this.IndexOf((T)((object)item));
- }
- return -1;
- }
- [__DynamicallyInvokable]
- public int IndexOf(T item, int index)
- {
- if (index > this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
- }
- return Array.IndexOf<T>(this._items, item, index, this._size - index);
- }
- [__DynamicallyInvokable]
- public int IndexOf(T item, int index, int count)
- {
- if (index > this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
- }
- if (count < 0 || index > this._size - count)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
- }
- return Array.IndexOf<T>(this._items, item, index, count);
- }
- [__DynamicallyInvokable]
- public void Insert(int index, T item)
- {
- if (index > this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
- }
- if (this._size == this._items.Length)
- {
- this.EnsureCapacity(this._size + 1);
- }
- if (index < this._size)
- {
- Array.Copy(this._items, index, this._items, index + 1, this._size - index);
- }
- this._items[index] = item;
- this._size++;
- this._version++;
- }
- [__DynamicallyInvokable]
- void IList.Insert(int index, object item)
- {
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(item, ExceptionArgument.item);
- try
- {
- this.Insert(index, (T)((object)item));
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
- }
- }
- [__DynamicallyInvokable]
- public void InsertRange(int index, IEnumerable<T> collection)
- {
- if (collection == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
- }
- if (index > this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
- }
- ICollection<T> collection2 = collection as ICollection<T>;
- if (collection2 != null)
- {
- int count = collection2.Count;
- if (count > 0)
- {
- this.EnsureCapacity(this._size + count);
- if (index < this._size)
- {
- Array.Copy(this._items, index, this._items, index + count, this._size - index);
- }
- if (this == collection2)
- {
- Array.Copy(this._items, 0, this._items, index, index);
- Array.Copy(this._items, index + count, this._items, index * 2, this._size - index);
- }
- else
- {
- T[] array = new T[count];
- collection2.CopyTo(array, 0);
- array.CopyTo(this._items, index);
- }
- this._size += count;
- }
- }
- else
- {
- using (IEnumerator<T> enumerator = collection.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- this.Insert(index++, enumerator.Current);
- }
- }
- }
- this._version++;
- }
- [__DynamicallyInvokable]
- public int LastIndexOf(T item)
- {
- if (this._size == 0)
- {
- return -1;
- }
- return this.LastIndexOf(item, this._size - 1, this._size);
- }
- [__DynamicallyInvokable]
- public int LastIndexOf(T item, int index)
- {
- if (index >= this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
- }
- return this.LastIndexOf(item, index, index + 1);
- }
- [__DynamicallyInvokable]
- public int LastIndexOf(T item, int index, int count)
- {
- if (this.Count != 0 && index < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (this.Count != 0 && count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (this._size == 0)
- {
- return -1;
- }
- if (index >= this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_BiggerThanCollection);
- }
- if (count > index + 1)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_BiggerThanCollection);
- }
- return Array.LastIndexOf<T>(this._items, item, index, count);
- }
- [__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
- public bool Remove(T item)
- {
- int num = this.IndexOf(item);
- if (num >= 0)
- {
- this.RemoveAt(num);
- return true;
- }
- return false;
- }
- [__DynamicallyInvokable]
- void IList.Remove(object item)
- {
- if (List<T>.IsCompatibleObject(item))
- {
- this.Remove((T)((object)item));
- }
- }
- [__DynamicallyInvokable]
- public int RemoveAll(Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
- int num = 0;
- while (num < this._size && !match(this._items[num]))
- {
- num++;
- }
- if (num >= this._size)
- {
- return 0;
- }
- int i = num + 1;
- while (i < this._size)
- {
- while (i < this._size && match(this._items[i]))
- {
- i++;
- }
- if (i < this._size)
- {
- this._items[num++] = this._items[i++];
- }
- }
- Array.Clear(this._items, num, this._size - num);
- int result = this._size - num;
- this._size = num;
- this._version++;
- return result;
- }
- [__DynamicallyInvokable]
- public void RemoveAt(int index)
- {
- if (index >= this._size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException();
- }
- this._size--;
- if (index < this._size)
- {
- Array.Copy(this._items, index + 1, this._items, index, this._size - index);
- }
- this._items[this._size] = default(T);
- this._version++;
- }
- [__DynamicallyInvokable]
- public void RemoveRange(int index, int count)
- {
- if (index < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (this._size - index < count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- }
- if (count > 0)
- {
- this._size -= count;
- if (index < this._size)
- {
- Array.Copy(this._items, index + count, this._items, index, this._size - index);
- }
- Array.Clear(this._items, this._size, count);
- this._version++;
- }
- }
- [__DynamicallyInvokable]
- public void Reverse()
- {
- this.Reverse(0, this.Count);
- }
- [__DynamicallyInvokable]
- public void Reverse(int index, int count)
- {
- if (index < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (this._size - index < count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- }
- Array.Reverse(this._items, index, count);
- this._version++;
- }
- [__DynamicallyInvokable]
- public void Sort()
- {
- this.Sort(0, this.Count, null);
- }
- [__DynamicallyInvokable]
- public void Sort(IComparer<T> comparer)
- {
- this.Sort(0, this.Count, comparer);
- }
- [__DynamicallyInvokable]
- public void Sort(int index, int count, IComparer<T> comparer)
- {
- if (index < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (this._size - index < count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- }
- Array.Sort<T>(this._items, index, count, comparer);
- this._version++;
- }
- [__DynamicallyInvokable]
- public void Sort(Comparison<T> comparison)
- {
- if (comparison == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
- if (this._size > 0)
- {
- IComparer<T> comparer = new Array.FunctorComparer<T>(comparison);
- Array.Sort<T>(this._items, 0, this._size, comparer);
- }
- }
- [__DynamicallyInvokable]
- public T[] ToArray()
- {
- T[] array = new T[this._size];
- Array.Copy(this._items, 0, array, 0, this._size);
- return array;
- }
- [__DynamicallyInvokable]
- public void TrimExcess()
- {
- int num = (int)((double)this._items.Length * 0.9);
- if (this._size < num)
- {
- this.Capacity = this._size;
- }
- }
- [__DynamicallyInvokable]
- public bool TrueForAll(Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
- for (int i = 0; i < this._size; i++)
- {
- if (!match(this._items[i]))
- {
- return false;
- }
- }
- return true;
- }
- internal static IList<T> Synchronized(List<T> list)
- {
- return new List<T>.SynchronizedList(list);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement