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)); }
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); }
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); }
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); }
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); }
private bool Equals(ObservableKeyValuePair <TKey, TValue> other) { return(_comparer.Equals(_key, other._key) && EqualityComparer <TValue> .Default.Equals(_value, other._value)); }
private void RaiseRemoved(ObservableKeyValuePair <TKey, TValue> item, int index) { RaiseCollectionChanged(); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index)); }
private void RaiseAdded(ObservableKeyValuePair <TKey, TValue> item, int index) { RaiseCollectionChanged(); item.PropertyChanging += RaiseItemChanging; OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)); }