- Timestamp:
- 04/18/10 02:27:02 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Collections/3.3/ObservableDictionary.cs
r3370 r3390 25 25 using System.ComponentModel; 26 26 using System.Linq; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;28 27 29 28 namespace HeuristicLab.Collections { 30 29 [Serializable] 31 [StorableClass]32 30 public class ObservableDictionary<TKey, TValue> : IObservableDictionary<TKey, TValue> { 33 [Storable] 34 private Dictionary<TKey, TValue> dict; 31 protected Dictionary<TKey, TValue> dict; 35 32 36 33 #region Properties 37 [Storable]38 private bool readOnlyView;39 public virtual bool ReadOnlyView {40 get { return readOnlyView; }41 set {42 if ((readOnlyView != value) && !((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly) {43 readOnlyView = value;44 OnReadOnlyViewChanged();45 OnPropertyChanged("ReadOnlyView");46 }47 }48 }49 50 34 public ICollection<TKey> Keys { 51 35 get { return dict.Keys; } … … 84 68 public ObservableDictionary() { 85 69 dict = new Dictionary<TKey, TValue>(); 86 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;87 70 } 88 71 public ObservableDictionary(int capacity) { 89 72 dict = new Dictionary<TKey, TValue>(capacity); 90 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;91 73 } 92 74 public ObservableDictionary(IEqualityComparer<TKey> comparer) { 93 75 dict = new Dictionary<TKey, TValue>(comparer); 94 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;95 76 } 96 77 public ObservableDictionary(IDictionary<TKey, TValue> dictionary) { 97 78 dict = new Dictionary<TKey, TValue>(dictionary); 98 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;99 79 } 100 80 public ObservableDictionary(int capacity, IEqualityComparer<TKey> comparer) { 101 81 dict = new Dictionary<TKey, TValue>(capacity, comparer); 102 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;103 82 } 104 83 public ObservableDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer) { 105 84 dict = new Dictionary<TKey, TValue>(dictionary, comparer); 106 readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;107 85 } 108 86 #endregion … … 200 178 #region Events 201 179 [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]209 180 public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsAdded; 210 181 protected virtual void OnItemsAdded(IEnumerable<KeyValuePair<TKey, TValue>> items) {
Note: See TracChangeset
for help on using the changeset viewer.