示例#1
0
 /// <summary>
 /// Adds an item to the collection if it is not already present.
 /// </summary>
 /// <param name="item">The item to add.</param>
 public override void Add(T item)
 {
     if (-1 == DistinctListItems.IndexOf(item))
     {
         base.Add(item);
     }
     //else do nothing.
 }
示例#2
0
        /// <summary>
        /// Inserts an item into the collection at the specified index,
        /// if the item is not already present.
        /// </summary>
        /// <param name="index">The index at which to insert the item.</param>
        /// <param name="item">The item to insert into the collection.</param>
        public override void Insert(int index, T item)
        {
            //Note: No error handling necessary.
            //      If the index is out of bounds, then let the list's insert method throw an exception.

            if (-1 == DistinctListItems.IndexOf(item))
            {
                base.Insert(index, item);
            }
            //else do nothing.
        }
示例#3
0
        /// <summary>
        /// Gets or sets the item at the specified index,
        /// unless the item already exists at another index.
        /// </summary>
        /// <param name="index">The zero-based index of the item to get or set.</param>
        /// <returns>Returns the item at the specified index.</returns>
        public override T this[int index]
        {
            get { return(base[index]); }
            set
            {
                int currentIndex = DistinctListItems.IndexOf(value);

                if (currentIndex == -1 || currentIndex == index)
                {
                    base[index] = value;
                }
                //else do nothing.
            }
        }