/// <summary> /// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </summary> /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. /// </exception> public void Clear() { ValueLock.EnterWriteLock(); try { Count = 0; } finally { ValueLock.ExitWriteLock(); } }
/// <summary> /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </summary> /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </param><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. /// </exception> public void Add(T item) { ValueLock.EnterWriteLock(); try { AutoGrow = true; base[Count++] = item; AutoGrow = false; } finally { ValueLock.ExitWriteLock(); } }
public T this[int index] { get { ValueLock.EnterReadLock(); try { if (index >= Count || index < 0) { string msg = string.Format("Tried to access item outside the array boundaries. {0}/{1}", index, Count); throw new ArgumentOutOfRangeException(msg); } return(base[index]); } finally { ValueLock.ExitReadLock(); } } set { if (index < 0) { throw new ArgumentOutOfRangeException("Tried to access item outside the array boundaries"); } try { ValueLock.EnterWriteLock(); if (index >= Count) { throw new ArgumentOutOfRangeException("Tried to access item outside the array boundaries"); } base[index] = value; } finally { ValueLock.ExitWriteLock(); } } }
/// <summary> /// Removes the <see cref="T:System.Collections.Generic.IList`1"/> item at the specified index. /// </summary> /// <param name="index">The zero-based index of the item to remove. /// </param><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1"/>. /// </exception><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IList`1"/> is read-only. /// </exception> public void RemoveAt(int index) { ValueLock.EnterWriteLock(); try { if ((index + 1) == Count) { Count--; return; } for (int i = index; i < Count - 1; i++) { this[i] = this[i + 1]; } Count--; } finally { ValueLock.ExitWriteLock(); } }
/// <summary> /// Inserts an item to the <see cref="T:System.Collections.Generic.IList`1"/> at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted. /// </param><param name="item">The object to insert into the <see cref="T:System.Collections.Generic.IList`1"/>. /// </param><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1"/>. /// </exception><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IList`1"/> is read-only. /// </exception> public void Insert(int index, T item) { ValueLock.EnterWriteLock(); try { if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException("index", "invalid index"); } Add(new T()); // make room for one more for (int i = Count - 1; i > index; i--) { this[i] = this[i - 1]; } this[index] = item; } finally { ValueLock.ExitWriteLock(); } }