Exemplo n.º 1
0
 /// <summary>
 /// Raises the <see cref="INotifyDictionaryChanged{TKey, TValue}.DictionaryChanged"/> event
 /// </summary>
 /// <param name="e">The event arguments</param>
 protected virtual void OnDictionaryChanged(NotifyDictionaryChangedEventArgs <TKey, TValue> e) => DictionaryChanged?.Invoke(this, e);
Exemplo n.º 2
0
 /// <summary>
 /// Raises the <see cref="INotifyDictionaryChanged.DictionaryChanged"/> event
 /// </summary>
 /// <param name="e">The event arguments</param>
 protected virtual void OnDictionaryChangedBoxed(NotifyDictionaryChangedEventArgs <object, object> e) => DictionaryChangedBoxed?.Invoke(this, e);
Exemplo n.º 3
0
        /// <summary>
        /// Calls <see cref="OnDictionaryChanged(NotifyDictionaryChangedEventArgs{TKey, TValue})"/> and also calls <see cref="OnCollectionChanged(NotifyCollectionChangedEventArgs)"/>, <see cref="OnDictionaryChangedBoxed(NotifyDictionaryChangedEventArgs{object, object})"/>, and <see cref="OnGenericCollectionChanged(NotifyGenericCollectionChangedEventArgs{KeyValuePair{TKey, TValue}})"/> when applicable
        /// </summary>
        /// <param name="e">The event arguments for <see cref="INotifyDictionaryChanged{TKey, TValue}.DictionaryChanged"/></param>
        protected virtual void OnChanged(NotifyDictionaryChangedEventArgs <TKey, TValue> e)
        {
            if (CollectionChanged != null)
            {
                switch (e.Action)
                {
                case NotifyDictionaryChangedAction.Add:
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, e.NewItems));
                    break;

                case NotifyDictionaryChangedAction.Remove:
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, e.OldItems));
                    break;

                case NotifyDictionaryChangedAction.Replace:
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, e.NewItems, e.OldItems));
                    break;

                case NotifyDictionaryChangedAction.Reset:
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            if (GenericCollectionChanged != null)
            {
                switch (e.Action)
                {
                case NotifyDictionaryChangedAction.Add:
                    OnGenericCollectionChanged(new NotifyGenericCollectionChangedEventArgs <KeyValuePair <TKey, TValue> >(NotifyCollectionChangedAction.Add, e.NewItems));
                    break;

                case NotifyDictionaryChangedAction.Remove:
                    OnGenericCollectionChanged(new NotifyGenericCollectionChangedEventArgs <KeyValuePair <TKey, TValue> >(NotifyCollectionChangedAction.Remove, e.OldItems));
                    break;

                case NotifyDictionaryChangedAction.Replace:
                    OnGenericCollectionChanged(new NotifyGenericCollectionChangedEventArgs <KeyValuePair <TKey, TValue> >(NotifyCollectionChangedAction.Replace, e.NewItems, e.OldItems));
                    break;

                case NotifyDictionaryChangedAction.Reset:
                    OnGenericCollectionChanged(new NotifyGenericCollectionChangedEventArgs <KeyValuePair <TKey, TValue> >(NotifyCollectionChangedAction.Reset));
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            if (DictionaryChangedBoxed != null)
            {
                switch (e.Action)
                {
                case NotifyDictionaryChangedAction.Add:
                    OnDictionaryChangedBoxed(new NotifyDictionaryChangedEventArgs <object, object>(NotifyDictionaryChangedAction.Add, e.NewItems.Select(kv => new KeyValuePair <object, object>(kv.Key, kv.Value))));
                    break;

                case NotifyDictionaryChangedAction.Remove:
                    OnDictionaryChangedBoxed(new NotifyDictionaryChangedEventArgs <object, object>(NotifyDictionaryChangedAction.Remove, e.OldItems.Select(kv => new KeyValuePair <object, object>(kv.Key, kv.Value))));
                    break;

                case NotifyDictionaryChangedAction.Replace:
                    OnDictionaryChangedBoxed(new NotifyDictionaryChangedEventArgs <object, object>(NotifyDictionaryChangedAction.Replace, e.NewItems.Select(kv => new KeyValuePair <object, object>(kv.Key, kv.Value)), e.OldItems.Select(kv => new KeyValuePair <object, object>(kv.Key, kv.Value))));
                    break;

                case NotifyDictionaryChangedAction.Reset:
                    OnDictionaryChangedBoxed(new NotifyDictionaryChangedEventArgs <object, object>(NotifyDictionaryChangedAction.Reset));
                    break;
                }
            }
            OnDictionaryChanged(e);
        }