예제 #1
0
        public virtual TData this[TKey1 key1, Tkey2 key2]
        {
            get
            {
                if (key1 == null && key2 == null)
                {
                    throw new ArgumentNullException("key1 and key2", "Key should not be nullable");
                }

                var key = new CompositeKey <TKey1, Tkey2>(key1, key2);
                return(_dictionary[key]);
            }
            set
            {
                CheckKeyParameters(key1, key2);
                var key = new CompositeKey <TKey1, Tkey2>(key1, key2);
                SetValue(key, value);
            }
        }
예제 #2
0
        public virtual void Remove(TKey1 key1, Tkey2 key2)
        {
            CheckKeyParameters(key1, key2);
            var key = new CompositeKey <TKey1, Tkey2>(key1, key2);

            if (_dictionary.ContainsKey(key))
            {
                _dictionary.Remove(key);
            }



            // remove from _idDictionary
            if (_idDictionary.ContainsKey(key1))
            {
                var dictionaryWithNames = _idDictionary[key1];
                if (dictionaryWithNames.ContainsKey(key2))
                {
                    dictionaryWithNames.Remove(key2);
                }

                if (dictionaryWithNames.Count == 0)
                {
                    _idDictionary.Remove(key1);
                }
            }

            // remove from _namedDictionary
            if (_namedDictionary.ContainsKey(key2))
            {
                var dictionaryWithId = _namedDictionary[key2];
                if (dictionaryWithId.ContainsKey(key1))
                {
                    dictionaryWithId.Remove(key1);
                }

                if (dictionaryWithId.Count == 0)
                {
                    _namedDictionary.Remove(key2);
                }
            }
        }
예제 #3
0
 private void SetValue(CompositeKey <TKey1, Tkey2> key, TData data)
 {
     _dictionary.Add(key, data);
 }