private void DispatchChange(NotifyDictionaryChangedEventArgs <TKey, TValue> args)
 {
     if (CollectionChanged != null)
     {
         CollectionChanged(this, args);
     }
 }
        internal void Add(TKey key, TValue value)
        {
            this.dictionary.Add(key, value);
            var dictArgs = new NotifyDictionaryChangedEventArgs <TKey, TValue> {
                Action = NotifyCollectionChangedAction.Add, NewItem = value, Key = key
            };

            DispatchChange(dictArgs);
        }
        internal bool Remove(TKey key)
        {
            TValue value    = this.dictionary.ContainsKey(key) ? this.dictionary[key] : default(TValue);
            bool   removed  = this.dictionary.Remove(key);
            var    dictArgs = new NotifyDictionaryChangedEventArgs <TKey, TValue> {
                Action = NotifyCollectionChangedAction.Remove, OldItem = value, Key = key
            };

            DispatchChange(dictArgs);

            return(removed);
        }
        internal void Clear()
        {
            foreach (TKey key in this.dictionary.Keys)
            {
                TValue value = this.dictionary[key];

                var dictArgs = new NotifyDictionaryChangedEventArgs <TKey, TValue> {
                    Action = NotifyCollectionChangedAction.Remove, OldItem = value
                };

                DispatchChange(dictArgs);
            }

            this.dictionary.Clear();
        }
        public TValue this[TKey key]
        {
            get
            {
                return(this.dictionary[key]);
            }
            internal set
            {
                TValue oldValue = this.dictionary.ContainsKey(key) ? this.dictionary[key] : default(TValue);
                this.dictionary[key] = value;

                var dictArgs = new NotifyDictionaryChangedEventArgs <TKey, TValue> {
                    Action = NotifyCollectionChangedAction.Replace, OldItem = oldValue, NewItem = value, Key = key
                };

                DispatchChange(dictArgs);
            }
        }