コード例 #1
0
        /// <summary>
        /// The one-dimensional array of type <see cref="ItemsValue"/> that is the destination of <see cref="ItemsValue"/>
        /// objects copied from <see cref="ICollection"/>. The array must have zero-based indexing.
        /// </summary>
        /// <param name="array">The one-dimensional array of <see cref="ItemsValue"/> that is the destination of the elements copied from the collection. The <see cref="Array"/> must have zero-based indexing.</param>
        /// <param name="index">The zero-based index in array at which copying begins.</param>
        public void CopyTo(ItemsValue[] array, int index)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }

            if (!(array is ItemsValue[] typedArray))
            {
                throw new InvalidCastException(nameof(array));
            }

            if (index < 0 || (typedArray.Length - index) < Count)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            if (_pairs != null)
            {
                foreach (string key in Keys)
                {
                    typedArray[index++] = new ItemsValue(key, this[key]);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Removes the element with the specified key from the collection.
 /// </summary>
 /// <param name="item">The <see cref="ItemsValue"/> to remove from the collection.</param>
 public void Remove(ItemsValue item)
 {
     if (_pairs != null)
     {
         _pairs.Remove(item.Key);
     }
 }
コード例 #3
0
 /// <summary>
 /// Removes the element with the specified key from the collection.
 /// </summary>
 /// <param name="key">The key to remove from the collection.</param>
 public void Remove(object key)
 {
     if (_pairs != null)
     {
         for (int i = 0; i < Count; i++)
         {
             ItemsValue nvp = (ItemsValue)_pairs[i];
             if (nvp.Key == key)
             {
                 _pairs.RemoveAt(i);
                 break;
             }
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Gets or sets the value associated with the specified key.
        /// </summary>
        /// <param name="key">The key whose value to get or set.</param>
        /// <returns>
        /// The value associated with the specified key. If the specified key is not found,
        /// attempting to get it returns null, and attempting to set it creates a new element
        /// using the specified key.
        /// </returns>
        public object this[object key]
        {
            get
            {
                if (_pairs == null)
                {
                    return(null);
                }

                for (int i = 0; i < Count; i++)
                {
                    ItemsValue kvp = (ItemsValue)_pairs[i];
                    if (kvp.Key == key)
                    {
                        return(kvp.Value);
                    }
                }
                return(null);
            }
            set
            {
                if (_pairs == null)
                {
                    _pairs = new ArrayList();
                }

                for (int i = 0; i < Count; i++)
                {
                    ItemsValue kvp = (ItemsValue)_pairs[i];
                    if (kvp.Key == key)
                    {
                        kvp.Value = value;
                        return;
                    }
                }
                _pairs.Add(new ItemsValue(key, value));
            }
        }