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

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

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

            if (_pairs != null)
            {
                foreach (Type key in Keys)
                {
                    typedArray[index++] = new FeatureValue(key, this[key]);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Removes the element with the specified key from the collection.
 /// </summary>
 /// <param name="item">The <see cref="FeatureValue"/> to remove from the collection.</param>
 public void Remove(FeatureValue item)
 {
     if (_pairs != null)
     {
         _pairs.Remove(item.Key);
     }
 }
Ejemplo 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(Type key)
 {
     if (_pairs != null)
     {
         for (int i = 0; i < Count; i++)
         {
             FeatureValue nvp = (FeatureValue)_pairs[i];
             if (nvp.Key == key)
             {
                 _pairs.RemoveAt(i);
                 break;
             }
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Determines whether the collection contains a specific key.
        /// </summary>
        /// <param name="key">The key to locate in the collection.</param>
        public bool ContainsKey(Type key)
        {
            if (_pairs == null)
            {
                return(false);
            }

            for (int i = 0; i < Count; i++)
            {
                FeatureValue kvp = (FeatureValue)_pairs[i];
                if (kvp.Key == key)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 5
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[Type key]
        {
            get
            {
                if (_pairs == null)
                {
                    return(null);
                }

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

                lock (_lock)
                {
                    _pairs.Add(new FeatureValue(key, value));
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the value associated with the specified key.
        /// </summary>
        /// <param name="key">The key of the value to get.</param>
        /// <param name="value">When this method returns, the value associated with the specified key, if the
        /// key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
        /// </param>
        /// <returns>
        /// <c>true</c> if the object that implements collection contains an element with the specified key; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException">Specified key is <c>null</c></exception>
        public bool TryGetValue(Type key, out object value)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

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

            value = default;
            return(false);
        }