Example #1
0
 /// <inheritdoc/>
 public TFlag this[TKey key]
 {
     get
     {
         ArgumentValidator.EnsureArgumentIsNotDefault(key, "key");
         TFlag value;
         bool  result = TryGetValue(key, out value);
         if (!result)
         {
             throw new KeyNotFoundException();
         }
         return(value);
     }
     set
     {
         ArgumentValidator.EnsureArgumentIsNotDefault(key, "key");
         this.EnsureNotLocked();
         int index = keys.IndexOf(key);
         if (index < 0)
         {
             Add(key, value);
         }
         else
         {
             flags[1 << index] = converter.ConvertForward(value);
         }
     }
 }
Example #2
0
        /// <inheritdoc/>
        public bool Remove(TKey key)
        {
            ArgumentValidator.EnsureArgumentIsNotDefault(key, "key");
            this.EnsureNotLocked();
            int index = keys.IndexOf(key);

            if (index < 0)
            {
                return(false);
            }
            keys.RemoveAt(index);
            int data      = flags.Data;
            int remainder = data & (0xFFFF << index);

            data ^= remainder;
            data |= (remainder >> 1) & (0xFFFF << index);
            flags = new BitVector32(data);
            return(true);
        }