示例#1
0
        protected virtual bool SetEntry(TKey key, TValue value)
        {
            var keyExists = KeyedEntryCollection.Contains(key);

            // if identical key/value pair already exists, nothing to do
            if (keyExists && value.Equals((TValue)KeyedEntryCollection[key].Value))
            {
                return(false);
            }

            // otherwise, remove the existing entry
            if (keyExists)
            {
                KeyedEntryCollection.Remove(key);
            }

            // add the new entry
            KeyedEntryCollection.Add(new DictionaryEntry(key, value));

            return(true);
        }
        protected override bool SetEntry(TKey key, TValue value)
        {
            var keyExists = KeyedEntryCollection.Contains(key);

            // if identical key/value pair already exists, nothing to do
            if (keyExists && value.Equals((TValue)KeyedEntryCollection[key].Value))
            {
                return(false);
            }

            // otherwise, remove the existing entry
            if (keyExists)
            {
                KeyedEntryCollection.Remove(key);
            }

            // add the new entry
            var entry = new DictionaryEntry(key, value);
            var index = GetInsertionIndexForEntry(entry);

            KeyedEntryCollection.Insert(index, entry);

            return(true);
        }
示例#3
0
 protected virtual bool RemoveEntry(TKey key)
 {
     // remove the entry
     return(KeyedEntryCollection.Remove(key));
 }