/// <summary> /// Inserts an item at the specified index /// </summary> /// /// <param name="index"> /// Zero-based index of the position to insert the item /// </param> /// <param name="item"> /// The item to insert. /// </param> public void Insert(int index, T item) { if (MutableList.Add(item)) { MutableListOrdered.Insert(index, item); Touch(); } }
/// <summary> /// Removes the item at the specified index. /// </summary> /// /// <exception cref="IndexOutOfRangeException"> /// Thrown when the index is outside the bound of the current set. /// </exception> /// /// <param name="index"> /// Zero-based index of the item to remove. /// </param> public void RemoveAt(int index) { if (index >= Count || Count == 0) { throw new IndexOutOfRangeException("Index out of range"); } T item = OrderedList.ElementAt(index); MutableList.Remove(item); MutableListOrdered.Remove(item); Touch(); }
/// <summary> /// Removes the given item from the SelectionSet /// </summary> /// /// <param name="item"> /// The item to remove. /// </param> /// /// <returns> /// true if it succeeds, false if it fails. /// </returns> public bool Remove(T item) { if (MutableList.Remove(item)) { MutableListOrdered.Remove(item); Touch(); return(true); } else { return(false); } }
/// <summary> /// Adds a new item to the SelectionSet /// </summary> /// /// <param name="item"> /// The item to add. /// </param> /// /// <returns> /// true if it succeeds, false if it fails. /// </returns> public bool Add(T item) { if (MutableList.Add(item)) { MutableListOrdered.Add(item); Touch(); return(true); } else { return(false); } }
/// <summary> /// Use after set operations that alter the list /// </summary> private void SynchronizeOrderedList() { int index = 0; while (index < MutableListOrdered.Count) { if (!MutableList.Contains(MutableListOrdered[index])) { MutableListOrdered.RemoveAt(index); } else { index++; } } }
/// <summary> /// Indexer to get or set items within this collection using array index syntax. /// </summary> /// /// <param name="index"> /// Zero-based index of the entry to access. /// </param> /// /// <returns> /// The indexed item. /// </returns> public T this[int index] { get { return(OrderedList.ElementAt(index)); } set { T item = OrderedList.ElementAt(index); MutableList.Remove(item); MutableList.Add(value); int i = MutableListOrdered.IndexOf(item); MutableListOrdered[i] = value; Touch(); } }