20 private readonly
int _version;
26 public T Current => _current;
32 if (_index == 0 || _index > _builder._size)
34 throw Error.EnumerationIsDone();
43 _version = builder._version;
45 _current =
default(
T);
53 public bool MoveNext()
55 if (_version == _builder._version)
57 if (_index < _builder._size)
59 _current = _builder._items[_index++];
62 _index = _builder._size + 1;
63 _current =
default(
T);
66 throw Error.CollectionModifiedWhileEnumerating();
71 if (_version != _builder._version)
73 throw Error.CollectionModifiedWhileEnumerating();
76 _current =
default(
T);
80 private const int DefaultCapacity = 4;
89 private object _syncRoot;
91 private static readonly
T[] _emptyArray =
new T[0];
103 ContractUtils.Requires(value >= _size,
"value");
104 if (value == _items.Length)
110 T[] array =
new T[value];
119 _items = _emptyArray;
131 public T this[
int index]
135 ContractUtils.Requires(index < _size,
"index");
136 return _items[index];
140 ContractUtils.Requires(index < _size,
"index");
141 _items[index] = value;
182 object IList.this[
int index]
190 ValidateNullValue(value,
"value");
193 this[index] = (
T)value;
195 catch (InvalidCastException)
197 ThrowInvalidTypeException(value,
"value");
219 if (_syncRoot ==
null)
230 _items = _emptyArray;
237 ContractUtils.Requires(capacity >= 0,
"capacity");
238 _items =
new T[capacity];
245 ContractUtils.Requires(collection !=
null,
"collection");
247 if (collection2 !=
null)
249 int count = collection2.
Count;
250 _items =
new T[count];
251 collection2.
CopyTo(_items, 0);
258 foreach (
T item
in collection)
270 return Array.IndexOf(_items, item, 0, _size);
278 ContractUtils.Requires(index <= _size,
"index");
279 if (_size == _items.Length)
281 EnsureCapacity(_size + 1);
285 Array.
Copy(_items, index, _items, index + 1, _size - index);
287 _items[index] = item;
296 ContractUtils.Requires(index >= 0 && index < _size,
"index");
300 Array.
Copy(_items, index + 1, _items, index, _size - index);
302 _items[_size] =
default(
T);
310 if (_size == _items.Length)
312 EnsureCapacity(_size + 1);
314 _items[_size++] = item;
336 for (
int i = 0; i < _size; i++)
338 if (_items[i] ==
null)
346 for (
int j = 0; j < _size; j++)
348 if (@
default.Equals(_items[j], item))
359 public void CopyTo(T[] array,
int arrayIndex)
361 Array.
Copy(_items, 0, array, arrayIndex, _size);
382 return new Enumerator(
this);
397 ValidateNullValue(value,
"value");
404 ThrowInvalidTypeException(value,
"value");
415 if (IsCompatibleObject(value))
427 if (IsCompatibleObject(value))
439 ValidateNullValue(value,
"value");
444 catch (InvalidCastException)
446 ThrowInvalidTypeException(value,
"value");
454 if (IsCompatibleObject(value))
465 ContractUtils.RequiresNotNull(array,
"array");
466 ContractUtils.Requires(array.Rank == 1,
"array");
467 Array.Copy(_items, 0, array, index, _size);
481 ContractUtils.Requires(index >= 0,
"index");
482 ContractUtils.Requires(count >= 0,
"count");
491 T[] array =
new T[_size];
500 T[] list = (_size != _items.Length) ?
ToArray() : _items;
501 _items = _emptyArray;
504 return new TrueReadOnlyCollection<T>(list);
507 private void EnsureCapacity(
int min)
509 if (_items.Length < min)
512 if (_items.Length != 0)
514 num = _items.Length * 2;
524 private static bool IsCompatibleObject(
object value)
530 return default(T) ==
null;
537 private static void ValidateNullValue(
object value,
string argument)
539 if (value ==
null &&
default(T) !=
null)
541 throw new ArgumentException(Strings.InvalidNullValue(typeof(T)), argument);
545 private static void ThrowInvalidTypeException(
object value,
string argument)
547 throw new ArgumentException(Strings.InvalidObjectType((value !=
null) ? ((
object)value.GetType()) : ((
object)
"null"), typeof(T)), argument);
void Clear()
Removes all items from the T:System.Runtime.CompilerServices.ReadOnlyCollectionBuilder`1.
object SyncRoot
Gets an object that can be used to synchronize access to the T:System.Collections....
Provides a base class for implementations of the T:System.Collections.Generic.IEqualityComparer`1 gen...
int Count
Returns number of elements in the ReadOnlyCollectionBuilder.
void Reset()
Sets the enumerator to its initial position, which is before the first element in the collection.
The builder for read only collection.
int Capacity
Gets and sets the capacity of this ReadOnlyCollectionBuilder.
Provides the base class for a generic read-only collection.
static void SuppressFinalize(object obj)
Requests that the common language runtime not call the finalizer for the specified object.
void RemoveAt(int index)
Removes the T:System.Runtime.CompilerServices.ReadOnlyCollectionBuilder`1 item at the specified index...
static void Clear(Array array, int index, int length)
Sets a range of elements in an array to the default value of each element type.
bool Contains(T item)
Determines whether the T:System.Runtime.CompilerServices.ReadOnlyCollectionBuilder`1 contains a speci...
Represents a non-generic collection of objects that can be individually accessed by index.
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
IEnumerator< T > GetEnumerator()
Returns an enumerator that iterates through the collection.
void Insert(int index, object value)
Inserts an item to the T:System.Collections.IList at the specified index.
static void Reverse(Array array)
Reverses the sequence of the elements in the entire one-dimensional T:System.Array.
The exception that is thrown for invalid casting or explicit conversion.
void Reverse()
Reverses the order of the elements in the entire T:System.Runtime.CompilerServices....
bool IsReadOnly
Gets a value indicating whether the T:System.Collections.IList is read-only.
void CopyTo(T[] array, int arrayIndex)
Copies the elements of the T:System.Runtime.CompilerServices.ReadOnlyCollectionBuilder`1 to an T:Syst...
int IndexOf(object value)
Determines the index of a specific item in the T:System.Collections.IList.
void Insert(int index, T item)
Inserts an item to the T:System.Runtime.CompilerServices.ReadOnlyCollectionBuilder`1 at the specified...
static EqualityComparer< T > Default
Returns a default equality comparer for the type specified by the generic argument.
void Reverse(int index, int count)
Reverses the order of the elements in the specified range.
bool IsFixedSize
Gets a value indicating whether the T:System.Collections.IList has a fixed size.
ReadOnlyCollectionBuilder(int capacity)
Constructs a ReadOnlyCollectionBuilder with a given initial capacity. The contents are empty but buil...
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
object Current
Gets the element in the collection at the current position of the enumerator.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
bool IsSynchronized
Gets a value indicating whether access to the T:System.Collections.ICollection is synchronized (threa...
ReadOnlyCollectionBuilder()
Constructs a ReadOnlyCollectionBuilder.
int Add(object value)
Adds an item to the T:System.Collections.IList.
bool Remove(T item)
Removes the first occurrence of a specific object from the T:System.Runtime.CompilerServices....
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
void Add(T item)
Adds an item to the T:System.Runtime.CompilerServices.ReadOnlyCollectionBuilder`1.
Controls the system garbage collector, a service that automatically reclaims unused memory.
ReadOnlyCollection< T > ToReadOnlyCollection()
Creates a T:System.Collections.ObjectModel.ReadOnlyCollection`1 containing all of the elements of the...
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
T [] ToArray()
Copies the elements of the T:System.Runtime.CompilerServices.ReadOnlyCollectionBuilder`1 to a new arr...
Specifies that the class can be serialized.
void Remove(object value)
Removes the first occurrence of a specific object from the T:System.Collections.IList.
bool Contains(object value)
Determines whether the T:System.Collections.IList contains a specific value.
int Count
Gets the number of elements contained in the T:System.Collections.ICollection.
Defines size, enumerators, and synchronization methods for all nongeneric collections.
void CopyTo(Array array, int index)
Copies the elements of the T:System.Collections.ICollection to an T:System.Array, starting at a parti...
ReadOnlyCollectionBuilder(IEnumerable< T > collection)
Constructs a ReadOnlyCollectionBuilder, copying contents of the given collection.
Provides atomic operations for variables that are shared by multiple threads.
Supports a simple iteration over a non-generic collection.
int IndexOf(T item)
Returns the index of the first occurrence of a given value in the builder.