예제 #1
0
        protected override bool AddEntry(TKey key, TValue value)
        {
            var entry = new DictionaryEntry(key, value);
            var index = GetInsertionIndexForEntry(entry);

            KeyedEntryCollection.Insert(index, entry);
            return(true);
        }
예제 #2
0
        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);
        }