コード例 #1
0
        private void RaiseReplaced(TKey key, TValue oldValue, TValue newValue, int index)
        {
            ValidationHelper.NotNull(key, "key");

            RaiseItemChanged();
            var oldItem = new ObservableKeyValuePair <TKey, TValue>(key, oldValue);
            var newItem = new ObservableKeyValuePair <TKey, TValue>(key, newValue);

            newItem.PropertyChanging += RaiseItemChanging;
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItem, oldItem, index));
        }
コード例 #2
0
        bool ICollection <ObservableKeyValuePair <TKey, TValue> > .Contains(ObservableKeyValuePair <TKey, TValue> item)
        {
            ValidationHelper.NotNull(item, "item");
            ValidationHelper.NotNull(item.Key, "item");
            Contract.Ensures(!Contract.Result <bool>() || ((ICollection <ObservableKeyValuePair <TKey, TValue> >) this).Count > 0);

            var result = ContainsKey(item.Key) && ContainsValue(item.Value);

            // NOTE: Lack of contracts
            Contract.Assume(!result || ((ICollection <ObservableKeyValuePair <TKey, TValue> >) this).Count > 0);
            return(result);
        }
コード例 #3
0
        public void Clear()
        {
            Contract.Ensures(Count == 0);

            CheckReentrancy();

            var items = new ObservableKeyValuePair <TKey, TValue> [Count];

            ((ICollection <ObservableKeyValuePair <TKey, TValue> >) this).CopyTo(items, 0);
            _cache.Clear();
            RaiseCleared(items);

            Contract.Assume(Count == 0);
        }
コード例 #4
0
        void ICollection <ObservableKeyValuePair <TKey, TValue> > .Add(ObservableKeyValuePair <TKey, TValue> item)
        {
            ValidationHelper.NotNull(item, "item");
            ValidationHelper.NotNull(item.Key, "item");
            Contract.Ensures(((ICollection <ObservableKeyValuePair <TKey, TValue> >) this).Count ==
                             Contract.OldValue(((ICollection <ObservableKeyValuePair <TKey, TValue> >) this).Count) + 1);

            var @this = (ICollection <ObservableKeyValuePair <TKey, TValue> >) this;

            var oldCount = @this.Count;

            CheckReentrancy();

            Add(item.Key, item.Value);
            RaiseAdded(item, IndexOf(item.Key));

            // NOTE: Lack of contracts
            Contract.Assume(@this.Count == oldCount + 1);
        }
コード例 #5
0
        bool ICollection <ObservableKeyValuePair <TKey, TValue> > .Remove(ObservableKeyValuePair <TKey, TValue> item)
        {
            ValidationHelper.NotNull(item, "item");
            ValidationHelper.NotNull(item.Key, "item");
            Contract.Ensures(!Contract.Result <bool>() ||
                             ((ICollection <ObservableKeyValuePair <TKey, TValue> >) this).Count ==
                             Contract.OldValue(((ICollection <ObservableKeyValuePair <TKey, TValue> >) this).Count) - 1);

            var @this = (ICollection <ObservableKeyValuePair <TKey, TValue> >) this;

            var oldCount = @this.Count;

            CheckReentrancy();

            var result = @this.Contains(item) && Remove(item.Key);

            RaiseRemoved(item, IndexOf(item.Key));

            // NOTE: Lack of contracts
            Contract.Assume(!result || @this.Count == oldCount - 1);
            return(result);
        }
コード例 #6
0
 private bool Equals(ObservableKeyValuePair <TKey, TValue> other)
 {
     return(_comparer.Equals(_key, other._key) && EqualityComparer <TValue> .Default.Equals(_value, other._value));
 }
コード例 #7
0
 private void RaiseRemoved(ObservableKeyValuePair <TKey, TValue> item, int index)
 {
     RaiseCollectionChanged();
     OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
 }
コード例 #8
0
 private void RaiseAdded(ObservableKeyValuePair <TKey, TValue> item, int index)
 {
     RaiseCollectionChanged();
     item.PropertyChanging += RaiseItemChanging;
     OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
 }