Exemple #1
0
        /// <summary>
        /// Removes the associated data for the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns><c>true</c> if the data was removed; <c>false</c> otherwise</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public bool RemoveData(object key)
        {
            if (key == null)
            {
                ThrowHelper.ArgumentNullException_key();
            }
            if (attachedDatas == null)
            {
                return(true);
            }

            for (int i = 0; i < count; i++)
            {
                if (attachedDatas[i].Key == key)
                {
                    if (i < count - 1)
                    {
                        Array.Copy(attachedDatas, i + 1, attachedDatas, i, count - i - 1);
                    }
                    count--;
                    attachedDatas[count] = new DataEntry();
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
 /// <summary>
 /// Stores a key/value pair for this instance.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <exception cref="ArgumentNullException">if key is null</exception>
 public void SetData(object key, object value)
 {
     if (key == null)
     {
         ThrowHelper.ArgumentNullException_key();
     }
     if (attachedDatas == null)
     {
         attachedDatas = new DataEntry[1];
     }
     else
     {
         for (int i = 0; i < count; i++)
         {
             if (attachedDatas[i].Key == key)
             {
                 attachedDatas[i].Value = value;
                 return;
             }
         }
         if (count == attachedDatas.Length)
         {
             var temp = new DataEntry[attachedDatas.Length + 1];
             Array.Copy(attachedDatas, 0, temp, 0, count);
             attachedDatas = temp;
         }
     }
     attachedDatas[count] = new DataEntry(key, value);
     count++;
 }
Exemple #3
0
            public void SetData(object key, object value)
            {
                if (key is null)
                {
                    ThrowHelper.ArgumentNullException_key();
                }

                DataEntry[] entries = _entries;
                int         count   = _count;

                for (int i = 0; i < entries.Length && i < count; i++)
                {
                    ref DataEntry entry = ref entries[i];
                    if (entry.Key == key)
                    {
                        entry.Value = value;
                        return;
                    }
                }
Exemple #4
0
 /// <summary>
 /// Gets the associated data for the specified key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <returns>The associated data or null if none</returns>
 /// <exception cref="ArgumentNullException">if key is null</exception>
 public object GetData(object key)
 {
     if (key == null)
     {
         ThrowHelper.ArgumentNullException_key();
     }
     if (attachedDatas == null)
     {
         return(null);
     }
     for (int i = 0; i < count; i++)
     {
         if (attachedDatas[i].Key == key)
         {
             return(attachedDatas[i].Value);
         }
     }
     return(null);
 }
Exemple #5
0
        /// <summary>
        /// Determines whether this instance contains the specified key data.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns><c>true</c> if a data with the key is stored</returns>
        /// <exception cref="ArgumentNullException">if key is null</exception>
        public bool ContainsData(object key)
        {
            if (key == null)
            {
                ThrowHelper.ArgumentNullException_key();
            }
            if (attachedDatas == null)
            {
                return(false);
            }

            for (int i = 0; i < count; i++)
            {
                if (attachedDatas[i].Key == key)
                {
                    return(true);
                }
            }
            return(false);
        }