- Timestamp:
- 04/13/10 06:41:56 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Collections/3.3/ObservableDictionary.cs
r3017 r3317 35 35 36 36 #region Properties 37 [Storable] 38 private bool readOnlyView; 39 public bool ReadOnlyView { 40 get { return readOnlyView; } 41 set { 42 if (readOnlyView != value) { 43 readOnlyView = value; 44 OnReadOnlyViewChanged(); 45 OnPropertyChanged("ReadOnlyView"); 46 } 47 } 48 } 49 37 50 public ICollection<TKey> Keys { 38 51 get { return dict.Keys; } … … 71 84 public ObservableDictionary() { 72 85 dict = new Dictionary<TKey, TValue>(); 86 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly; 73 87 } 74 88 public ObservableDictionary(int capacity) { 75 89 dict = new Dictionary<TKey, TValue>(capacity); 90 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly; 76 91 } 77 92 public ObservableDictionary(IEqualityComparer<TKey> comparer) { 78 93 dict = new Dictionary<TKey, TValue>(comparer); 94 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly; 79 95 } 80 96 public ObservableDictionary(IDictionary<TKey, TValue> dictionary) { 81 97 dict = new Dictionary<TKey, TValue>(dictionary); 98 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly; 82 99 } 83 100 public ObservableDictionary(int capacity, IEqualityComparer<TKey> comparer) { 84 101 dict = new Dictionary<TKey, TValue>(capacity, comparer); 102 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly; 85 103 } 86 104 public ObservableDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer) { 87 105 dict = new Dictionary<TKey, TValue>(dictionary, comparer); 106 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly; 88 107 } 89 108 #endregion … … 181 200 #region Events 182 201 [field: NonSerialized] 202 public event EventHandler ReadOnlyViewChanged; 203 protected virtual void OnReadOnlyViewChanged() { 204 EventHandler handler = ReadOnlyViewChanged; 205 if (handler != null) handler(this, EventArgs.Empty); 206 } 207 208 [field: NonSerialized] 183 209 public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsAdded; 184 210 protected virtual void OnItemsAdded(IEnumerable<KeyValuePair<TKey, TValue>> items) { 185 if (ItemsAdded != null)186 ItemsAdded(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items));211 CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> handler = ItemsAdded; 212 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items)); 187 213 } 188 214 … … 190 216 public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsRemoved; 191 217 protected virtual void OnItemsRemoved(IEnumerable<KeyValuePair<TKey, TValue>> items) { 192 if (ItemsRemoved != null)193 ItemsRemoved(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items));218 CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> handler = ItemsRemoved; 219 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items)); 194 220 } 195 221 … … 197 223 public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsReplaced; 198 224 protected virtual void OnItemsReplaced(IEnumerable<KeyValuePair<TKey, TValue>> items, IEnumerable<KeyValuePair<TKey, TValue>> oldItems) { 199 if (ItemsReplaced != null)200 ItemsReplaced(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems));225 CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> handler = ItemsReplaced; 226 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems)); 201 227 } 202 228 … … 204 230 public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> CollectionReset; 205 231 protected virtual void OnCollectionReset(IEnumerable<KeyValuePair<TKey, TValue>> items, IEnumerable<KeyValuePair<TKey, TValue>> oldItems) { 206 if (CollectionReset != null)207 CollectionReset(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems));232 CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> handler = CollectionReset; 233 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems)); 208 234 } 209 235 … … 211 237 public event PropertyChangedEventHandler PropertyChanged; 212 238 protected virtual void OnPropertyChanged(string propertyName) { 213 if (PropertyChanged != null)214 PropertyChanged(this, new PropertyChangedEventArgs(propertyName));239 PropertyChangedEventHandler handler = PropertyChanged; 240 if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); 215 241 } 216 242 #endregion
Note: See TracChangeset
for help on using the changeset viewer.