Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/13/10 06:41:56 (14 years ago)
Author:
swagner
Message:

Implemented ReadOnlyView property for items (#969).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableDictionary.cs

    r3017 r3317  
    3535
    3636    #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
    3750    public ICollection<TKey> Keys {
    3851      get { return dict.Keys; }
     
    7184    public ObservableDictionary() {
    7285      dict = new Dictionary<TKey, TValue>();
     86      readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;
    7387    }
    7488    public ObservableDictionary(int capacity) {
    7589      dict = new Dictionary<TKey, TValue>(capacity);
     90      readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;
    7691    }
    7792    public ObservableDictionary(IEqualityComparer<TKey> comparer) {
    7893      dict = new Dictionary<TKey, TValue>(comparer);
     94      readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;
    7995    }
    8096    public ObservableDictionary(IDictionary<TKey, TValue> dictionary) {
    8197      dict = new Dictionary<TKey, TValue>(dictionary);
     98      readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;
    8299    }
    83100    public ObservableDictionary(int capacity, IEqualityComparer<TKey> comparer) {
    84101      dict = new Dictionary<TKey, TValue>(capacity, comparer);
     102      readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;
    85103    }
    86104    public ObservableDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer) {
    87105      dict = new Dictionary<TKey, TValue>(dictionary, comparer);
     106      readOnlyView = ((ICollection<KeyValuePair<TKey, TValue>>)dict).IsReadOnly;
    88107    }
    89108    #endregion
     
    181200    #region Events
    182201    [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]
    183209    public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsAdded;
    184210    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));
    187213    }
    188214
     
    190216    public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsRemoved;
    191217    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));
    194220    }
    195221
     
    197223    public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsReplaced;
    198224    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));
    201227    }
    202228
     
    204230    public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> CollectionReset;
    205231    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));
    208234    }
    209235
     
    211237    public event PropertyChangedEventHandler PropertyChanged;
    212238    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));
    215241    }
    216242    #endregion
Note: See TracChangeset for help on using the changeset viewer.