Ejemplo n.º 1
0
        /// <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();
            }
        }
Ejemplo n.º 2
0
        /// <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();
        }
Ejemplo n.º 3
0
        /// <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);
            }
        }
Ejemplo n.º 4
0
        /// <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);
            }
        }
Ejemplo n.º 5
0
        /// <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++;
                }
            }
        }
Ejemplo n.º 6
0
        /// <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();
            }
        }