示例#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 override bool AddEntry(TKey key, TValue value)
        {
            var entry = new DictionaryEntry(key, value);
            var index = GetInsertionIndexForEntry(entry);

            KeyedEntryCollection.Insert(index, entry);
            return(true);
        }
        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);
        }
        protected virtual bool ClearEntries()
        {
            // check whether there are entries to clear
            bool result = (Count > 0);

            if (result)
            {
                // if so, clear the dictionary
                KeyedEntryCollection.Clear();
            }
            return(result);
        }
示例#5
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);
        }
示例#7
0
 protected virtual bool RemoveEntry(TKey key)
 {
     // remove the entry
     return(KeyedEntryCollection.Remove(key));
 }
示例#8
0
 protected virtual bool AddEntry(TKey key, TValue value)
 {
     KeyedEntryCollection.Add(new DictionaryEntry(key, value));
     return(true);
 }
示例#9
0
 bool IDictionary <TKey, TValue> .ContainsKey(TKey key)
 {
     return(KeyedEntryCollection.Contains(key));
 }
示例#10
0
 bool ICollection <KeyValuePair <TKey, TValue> > .Contains(KeyValuePair <TKey, TValue> kvp)
 {
     return(KeyedEntryCollection.Contains(kvp.Key));
 }
示例#11
0
 bool IDictionary.Contains(object key)
 {
     return(KeyedEntryCollection.Contains((TKey)key));
 }
示例#12
0
 public bool ContainsKey(TKey key)
 {
     return(KeyedEntryCollection.Contains(key));
 }