Exemplo n.º 1
0
        /// <summary>
        /// The one-dimensional array of type <see cref="RouteValue"/> that is the destination of <see cref="RouteValue"/>
        /// objects copied from <see cref="ICollection"/>. The array must have zero-based indexing.
        /// </summary>
        /// <param name="array">The one-dimensional array of <see cref="RouteValue"/> 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(RouteValue[] array, int index)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }

            if (!(array is RouteValue[] 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 RouteValue(key, this[key]);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Removes the element with the specified key from the collection.
 /// </summary>
 /// <param name="item">The <see cref="RouteValue"/> to remove from the collection.</param>
 public void Remove(RouteValue item)
 {
     if (_pairs != null)
     {
         _pairs.Remove(item.Key);
     }
 }
Exemplo n.º 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(string key)
 {
     if (_pairs != null)
     {
         for (int i = 0; i < Count; i++)
         {
             RouteValue nvp = (RouteValue)_pairs[i];
             if (nvp.Key == key)
             {
                 _pairs.RemoveAt(i);
                 break;
             }
         }
     }
 }
Exemplo n.º 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 string[] this[string key]
        {
            get
            {
                if (_pairs == null)
                {
                    return(null);
                }

                for (int i = 0; i < Count; i++)
                {
                    RouteValue kvp = (RouteValue)_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++)
                {
                    RouteValue kvp = (RouteValue)_pairs[i];
                    if (kvp.Key == key)
                    {
                        kvp.Value = value;
                        return;
                    }
                }

                _pairs.Add(new RouteValue(key, value));
            }
        }