Example #1
0
        public bool TryGetValue(TKey key, out TValue value)
        {
            var result = KeyedEntryCollection.Contains(key);

            value = result ? (TValue)KeyedEntryCollection[key].Value : default(TValue);
            return(result);
        }
        protected int GetIndexAndEntryForKey(TKey key, out DictionaryEntry entry)
        {
            entry = new DictionaryEntry();
            int index = -1;

            if (KeyedEntryCollection.Contains(key))
            {
                entry = KeyedEntryCollection[key];
                index = KeyedEntryCollection.IndexOf(entry);
            }
            return(index);
        }
Example #3
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);
        }
Example #5
0
 bool IDictionary <TKey, TValue> .ContainsKey(TKey key)
 {
     return(KeyedEntryCollection.Contains(key));
 }
Example #6
0
 bool ICollection <KeyValuePair <TKey, TValue> > .Contains(KeyValuePair <TKey, TValue> kvp)
 {
     return(KeyedEntryCollection.Contains(kvp.Key));
 }
Example #7
0
 bool IDictionary.Contains(object key)
 {
     return(KeyedEntryCollection.Contains((TKey)key));
 }
Example #8
0
 public bool ContainsKey(TKey key)
 {
     return(KeyedEntryCollection.Contains(key));
 }