Free cookie consent management tool by TermsFeed Policy Generator

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

Implemented ReadOnlyView property for items (#969).

Location:
trunk/sources/HeuristicLab.Collections/3.3
Files:
14 edited

Legend:

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

    r2832 r3317  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.ComponentModel;
     
    2526namespace HeuristicLab.Collections {
    2627  public interface IObservableArray<T> : IList<T>, INotifyObservableArrayItemsChanged<T>, INotifyPropertyChanged {
     28    bool ReadOnlyView { get; set; }
    2729    int Length { get; }
     30
     31    event EventHandler ReadOnlyViewChanged;
    2832  }
    2933}
  • trunk/sources/HeuristicLab.Collections/3.3/IObservableCollection.cs

    r2832 r3317  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.ComponentModel;
    2425
    2526namespace HeuristicLab.Collections {
    26   public interface IObservableCollection<T> : ICollection<T>, INotifyObservableCollectionItemsChanged<T>, INotifyPropertyChanged { }
     27  public interface IObservableCollection<T> : ICollection<T>, INotifyObservableCollectionItemsChanged<T>, INotifyPropertyChanged {
     28    bool ReadOnlyView { get; set; }
     29
     30    event EventHandler ReadOnlyViewChanged;
     31  }
    2732}
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableArray.cs

    r3286 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 int Length {
    3851      get { return array.Length; }
     
    6376    public ObservableArray() {
    6477      array = new T[0];
     78      readOnlyView = array.IsReadOnly;
    6579    }
    6680    public ObservableArray(int length) {
    6781      array = new T[length];
     82      readOnlyView = array.IsReadOnly;
    6883    }
    6984    public ObservableArray(T[] array) {
    7085      this.array = (T[])array.Clone();
     86      readOnlyView = array.IsReadOnly;
    7187    }
    7288    public ObservableArray(IEnumerable<T> collection) {
    7389      array = collection.ToArray();
     90      readOnlyView = array.IsReadOnly;
    7491    }
    7592    #endregion
     
    281298    #region Events
    282299    [field: NonSerialized]
     300    public event EventHandler ReadOnlyViewChanged;
     301    protected virtual void OnReadOnlyViewChanged() {
     302      EventHandler handler = ReadOnlyViewChanged;
     303      if (handler != null) handler(this, EventArgs.Empty);
     304    }
     305
     306    [field: NonSerialized]
    283307    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced;
    284308    protected virtual void OnItemsReplaced(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    285       if (ItemsReplaced != null)
    286         ItemsReplaced(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     309      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsReplaced;
     310      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    287311    }
    288312
     
    290314    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsMoved;
    291315    protected virtual void OnItemsMoved(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    292       if (ItemsMoved != null)
    293         ItemsMoved(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     316      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsMoved;
     317      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    294318    }
    295319
     
    297321    public event CollectionItemsChangedEventHandler<IndexedItem<T>> CollectionReset;
    298322    protected virtual void OnCollectionReset(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    299       if (CollectionReset != null)
    300         CollectionReset(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     323      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = CollectionReset;
     324      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    301325    }
    302326
     
    304328    public event PropertyChangedEventHandler PropertyChanged;
    305329    protected virtual void OnPropertyChanged(string propertyName) {
    306       if (PropertyChanged != null)
    307         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     330      PropertyChangedEventHandler handler = PropertyChanged;
     331      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    308332    }
    309333    #endregion
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableCollection.cs

    r3286 r3317  
    3434
    3535    #region Properties
     36    [Storable]
     37    private bool readOnlyView;
     38    public bool ReadOnlyView {
     39      get { return readOnlyView; }
     40      set {
     41        if (readOnlyView != value) {
     42          readOnlyView = value;
     43          OnReadOnlyViewChanged();
     44          OnPropertyChanged("ReadOnlyView");
     45        }
     46      }
     47    }
     48
    3649    public int Capacity {
    3750      get { return list.Capacity; }
     
    5467    public ObservableCollection() {
    5568      list = new List<T>();
     69      readOnlyView = ((ICollection<T>)list).IsReadOnly;
    5670    }
    5771    public ObservableCollection(int capacity) {
    5872      list = new List<T>(capacity);
     73      readOnlyView = ((ICollection<T>)list).IsReadOnly;
    5974    }
    6075    public ObservableCollection(IEnumerable<T> collection) {
    6176      list = new List<T>(collection);
     77      readOnlyView = ((ICollection<T>)list).IsReadOnly;
    6278    }
    6379    #endregion
     
    189205    #region Events
    190206    [field: NonSerialized]
     207    public event EventHandler ReadOnlyViewChanged;
     208    protected virtual void OnReadOnlyViewChanged() {
     209      EventHandler handler = ReadOnlyViewChanged;
     210      if (handler != null) handler(this, EventArgs.Empty);
     211    }
     212
     213    [field: NonSerialized]
    191214    public event CollectionItemsChangedEventHandler<T> ItemsAdded;
    192215    protected virtual void OnItemsAdded(IEnumerable<T> items) {
    193       if (ItemsAdded != null)
    194         ItemsAdded(this, new CollectionItemsChangedEventArgs<T>(items));
     216      CollectionItemsChangedEventHandler<T> handler = ItemsAdded;
     217      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    195218    }
    196219
     
    198221    public event CollectionItemsChangedEventHandler<T> ItemsRemoved;
    199222    protected virtual void OnItemsRemoved(IEnumerable<T> items) {
    200       if (ItemsRemoved != null)
    201         ItemsRemoved(this, new CollectionItemsChangedEventArgs<T>(items));
     223      CollectionItemsChangedEventHandler<T> handler = ItemsRemoved;
     224      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    202225    }
    203226
     
    205228    public event CollectionItemsChangedEventHandler<T> CollectionReset;
    206229    protected virtual void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) {
    207       if (CollectionReset != null)
    208         CollectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
     230      CollectionItemsChangedEventHandler<T> handler = CollectionReset;
     231      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
    209232    }
    210233
     
    212235    public event PropertyChangedEventHandler PropertyChanged;
    213236    protected virtual void OnPropertyChanged(string propertyName) {
    214       if (PropertyChanged != null)
    215         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     237      PropertyChangedEventHandler handler = PropertyChanged;
     238      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    216239    }
    217240    #endregion
  • 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
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableKeyedCollection.cs

    r3286 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 int Count {
    3851      get { return dict.Count; }
     
    5568    protected ObservableKeyedCollection() {
    5669      dict = new Dictionary<TKey, TItem>();
     70      readOnlyView = ((ICollection<KeyValuePair<TKey, TItem>>)dict).IsReadOnly;
    5771    }
    5872    protected ObservableKeyedCollection(int capacity) {
    5973      dict = new Dictionary<TKey, TItem>(capacity);
     74      readOnlyView = ((ICollection<KeyValuePair<TKey, TItem>>)dict).IsReadOnly;
    6075    }
    6176    protected ObservableKeyedCollection(IEqualityComparer<TKey> comparer) {
    6277      dict = new Dictionary<TKey, TItem>(comparer);
     78      readOnlyView = ((ICollection<KeyValuePair<TKey, TItem>>)dict).IsReadOnly;
    6379    }
    6480    protected ObservableKeyedCollection(IEnumerable<TItem> collection) {
     
    6783      foreach (TItem item in collection)
    6884        dict.Add(GetKeyForItem(item), item);
     85      readOnlyView = ((ICollection<KeyValuePair<TKey, TItem>>)dict).IsReadOnly;
    6986    }
    7087    protected ObservableKeyedCollection(int capacity, IEqualityComparer<TKey> comparer) {
    7188      dict = new Dictionary<TKey, TItem>(capacity, comparer);
     89      readOnlyView = ((ICollection<KeyValuePair<TKey, TItem>>)dict).IsReadOnly;
    7290    }
    7391    protected ObservableKeyedCollection(IEnumerable<TItem> collection, IEqualityComparer<TKey> comparer) {
     
    7694      foreach (TItem item in collection)
    7795        dict.Add(GetKeyForItem(item), item);
     96      readOnlyView = ((ICollection<KeyValuePair<TKey, TItem>>)dict).IsReadOnly;
    7897    }
    7998    #endregion
     
    250269    #region Events
    251270    [field: NonSerialized]
     271    public event EventHandler ReadOnlyViewChanged;
     272    protected virtual void OnReadOnlyViewChanged() {
     273      EventHandler handler = ReadOnlyViewChanged;
     274      if (handler != null) handler(this, EventArgs.Empty);
     275    }
     276
     277    [field: NonSerialized]
    252278    public event CollectionItemsChangedEventHandler<TItem> ItemsAdded;
    253279    protected virtual void OnItemsAdded(IEnumerable<TItem> items) {
    254       if (ItemsAdded != null)
    255         ItemsAdded(this, new CollectionItemsChangedEventArgs<TItem>(items));
     280      CollectionItemsChangedEventHandler<TItem> handler = ItemsAdded;
     281      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<TItem>(items));
    256282    }
    257283
     
    259285    public event CollectionItemsChangedEventHandler<TItem> ItemsRemoved;
    260286    protected virtual void OnItemsRemoved(IEnumerable<TItem> items) {
    261       if (ItemsRemoved != null)
    262         ItemsRemoved(this, new CollectionItemsChangedEventArgs<TItem>(items));
     287      CollectionItemsChangedEventHandler<TItem> handler = ItemsRemoved;
     288      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<TItem>(items));
    263289    }
    264290
     
    266292    public event CollectionItemsChangedEventHandler<TItem> ItemsReplaced;
    267293    protected virtual void OnItemsReplaced(IEnumerable<TItem> items, IEnumerable<TItem> oldItems) {
    268       if (ItemsReplaced != null)
    269         ItemsReplaced(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems));
     294      CollectionItemsChangedEventHandler<TItem> handler = ItemsReplaced;
     295      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems));
    270296    }
    271297
     
    273299    public event CollectionItemsChangedEventHandler<TItem> CollectionReset;
    274300    protected virtual void OnCollectionReset(IEnumerable<TItem> items, IEnumerable<TItem> oldItems) {
    275       if (CollectionReset != null)
    276         CollectionReset(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems));
     301      CollectionItemsChangedEventHandler<TItem> handler = CollectionReset;
     302      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems));
    277303    }
    278304
     
    280306    public event PropertyChangedEventHandler PropertyChanged;
    281307    protected virtual void OnPropertyChanged(string propertyName) {
    282       if (PropertyChanged != null)
    283         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     308      PropertyChangedEventHandler handler = PropertyChanged;
     309      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    284310    }
    285311    #endregion
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableList.cs

    r3286 r3317  
    3434
    3535    #region Properties
     36    [Storable]
     37    private bool readOnlyView;
     38    public bool ReadOnlyView {
     39      get { return readOnlyView; }
     40      set {
     41        if (readOnlyView != value) {
     42          readOnlyView = value;
     43          OnReadOnlyViewChanged();
     44          OnPropertyChanged("ReadOnlyView");
     45        }
     46      }
     47    }
     48
    3649    public int Capacity {
    3750      get { return list.Capacity; }
     
    6881    public ObservableList() {
    6982      list = new List<T>();
     83      readOnlyView = ((ICollection<T>)list).IsReadOnly;
    7084    }
    7185    public ObservableList(int capacity) {
    7286      list = new List<T>(capacity);
     87      readOnlyView = ((ICollection<T>)list).IsReadOnly;
    7388    }
    7489    public ObservableList(IEnumerable<T> collection) {
    7590      list = new List<T>(collection);
     91      readOnlyView = ((ICollection<T>)list).IsReadOnly;
    7692    }
    7793    #endregion
     
    375391    #region Events
    376392    [field: NonSerialized]
     393    public event EventHandler ReadOnlyViewChanged;
     394    protected virtual void OnReadOnlyViewChanged() {
     395      EventHandler handler = ReadOnlyViewChanged;
     396      if (handler != null) handler(this, EventArgs.Empty);
     397    }
     398
     399    [field: NonSerialized]
    377400    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsAdded;
    378401    protected virtual void OnItemsAdded(IEnumerable<IndexedItem<T>> items) {
    379       if (ItemsAdded != null)
    380         ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items));
     402      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsAdded;
     403      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items));
    381404    }
    382405
     
    388411    }
    389412    private void OnItemsAdded(IEnumerable<T> items) {
    390       if (itemsAdded != null)
    391         itemsAdded(this, new CollectionItemsChangedEventArgs<T>(items));
     413      CollectionItemsChangedEventHandler<T> handler = itemsAdded;
     414      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    392415    }
    393416
     
    395418    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved;
    396419    protected virtual void OnItemsRemoved(IEnumerable<IndexedItem<T>> items) {
    397       if (ItemsRemoved != null)
    398         ItemsRemoved(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items));
     420      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsRemoved;
     421      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items));
    399422    }
    400423
     
    406429    }
    407430    private void OnItemsRemoved(IEnumerable<T> items) {
    408       if (itemsRemoved != null)
    409         itemsRemoved(this, new CollectionItemsChangedEventArgs<T>(items));
     431      CollectionItemsChangedEventHandler<T> handler = itemsRemoved;
     432      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    410433    }
    411434
     
    413436    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced;
    414437    protected virtual void OnItemsReplaced(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    415       if (ItemsReplaced != null)
    416         ItemsReplaced(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     438      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsReplaced;
     439      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    417440    }
    418441
     
    420443    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsMoved;
    421444    protected virtual void OnItemsMoved(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    422       if (ItemsMoved != null)
    423         ItemsMoved(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     445      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsMoved;
     446      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    424447    }
    425448
     
    427450    public event CollectionItemsChangedEventHandler<IndexedItem<T>> CollectionReset;
    428451    protected virtual void OnCollectionReset(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    429       if (CollectionReset != null)
    430         CollectionReset(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     452      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = CollectionReset;
     453      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    431454    }
    432455
     
    438461    }
    439462    private void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) {
    440       if (collectionReset != null)
    441         collectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
     463      CollectionItemsChangedEventHandler<T> handler = collectionReset;
     464      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
    442465    }
    443466
     
    445468    public event PropertyChangedEventHandler PropertyChanged;
    446469    protected virtual void OnPropertyChanged(string propertyName) {
    447       if (PropertyChanged != null)
    448         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     470      PropertyChangedEventHandler handler = PropertyChanged;
     471      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    449472    }
    450473    #endregion
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableSet.cs

    r3286 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 IEqualityComparer<T> Comparer {
    3851      get { return set.Comparer; }
     
    4962    public ObservableSet() {
    5063      set = new HashSet<T>();
     64      readOnlyView = ((ICollection<T>)set).IsReadOnly;
    5165    }
    5266    public ObservableSet(IEnumerable<T> collection) {
    5367      set = new HashSet<T>(collection);
     68      readOnlyView = ((ICollection<T>)set).IsReadOnly;
    5469    }
    5570    public ObservableSet(IEqualityComparer<T> comparer) {
    5671      set = new HashSet<T>(comparer);
     72      readOnlyView = ((ICollection<T>)set).IsReadOnly;
    5773    }
    5874    public ObservableSet(IEnumerable<T> collection, IEqualityComparer<T> comparer) {
    5975      set = new HashSet<T>(collection, comparer);
     76      readOnlyView = ((ICollection<T>)set).IsReadOnly;
    6077    }
    6178    #endregion
     
    227244    #region Events
    228245    [field: NonSerialized]
     246    public event EventHandler ReadOnlyViewChanged;
     247    protected virtual void OnReadOnlyViewChanged() {
     248      EventHandler handler = ReadOnlyViewChanged;
     249      if (handler != null) handler(this, EventArgs.Empty);
     250    }
     251
     252    [field: NonSerialized]
    229253    public event CollectionItemsChangedEventHandler<T> ItemsAdded;
    230254    protected virtual void OnItemsAdded(IEnumerable<T> items) {
    231       if (ItemsAdded != null)
    232         ItemsAdded(this, new CollectionItemsChangedEventArgs<T>(items));
     255      CollectionItemsChangedEventHandler<T> handler = ItemsAdded;
     256      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    233257    }
    234258
     
    236260    public event CollectionItemsChangedEventHandler<T> ItemsRemoved;
    237261    protected virtual void OnItemsRemoved(IEnumerable<T> items) {
    238       if (ItemsRemoved != null)
    239         ItemsRemoved(this, new CollectionItemsChangedEventArgs<T>(items));
     262      CollectionItemsChangedEventHandler<T> handler = ItemsRemoved;
     263      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    240264    }
    241265
     
    243267    public event CollectionItemsChangedEventHandler<T> CollectionReset;
    244268    protected virtual void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) {
    245       if (CollectionReset != null)
    246         CollectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
     269      CollectionItemsChangedEventHandler<T> handler = CollectionReset;
     270      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
    247271    }
    248272
     
    250274    public event PropertyChangedEventHandler PropertyChanged;
    251275    protected virtual void OnPropertyChanged(string propertyName) {
    252       if (PropertyChanged != null)
    253         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     276      PropertyChangedEventHandler handler = PropertyChanged;
     277      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    254278    }
    255279    #endregion
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableArray.cs

    r3019 r3317  
    3434
    3535    #region Properties
     36    public bool ReadOnlyView {
     37      get { return true; }
     38      set { throw new NotSupportedException(); }
     39    }
     40
    3641    public int Length {
    3742      get { return array.Length; }
     
    117122    }
    118123
     124    event EventHandler IObservableArray<T>.ReadOnlyViewChanged {
     125      add { }
     126      remove { }
     127    }
     128
    119129    [field: NonSerialized]
    120130    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced;
    121131    protected virtual void OnItemsReplaced(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    122       if (ItemsReplaced != null)
    123         ItemsReplaced(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     132      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsReplaced;
     133      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    124134    }
    125135
     
    127137    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsMoved;
    128138    protected virtual void OnItemsMoved(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    129       if (ItemsMoved != null)
    130         ItemsMoved(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     139      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsMoved;
     140      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    131141    }
    132142
     
    134144    public event CollectionItemsChangedEventHandler<IndexedItem<T>> CollectionReset;
    135145    protected virtual void OnCollectionReset(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    136       if (CollectionReset != null)
    137         CollectionReset(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     146      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = CollectionReset;
     147      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    138148    }
    139149
     
    141151    public event PropertyChangedEventHandler PropertyChanged;
    142152    protected virtual void OnPropertyChanged(string propertyName) {
    143       if (PropertyChanged != null)
    144         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     153      PropertyChangedEventHandler handler = PropertyChanged;
     154      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    145155    }
    146156
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableCollection.cs

    r3019 r3317  
    3434
    3535    #region Properties
     36    public bool ReadOnlyView {
     37      get { return true; }
     38      set { throw new NotSupportedException(); }
     39    }
     40
    3641    public int Count {
    3742      get { return collection.Count; }
     
    95100    }
    96101
     102    event EventHandler IObservableCollection<T>.ReadOnlyViewChanged {
     103      add { }
     104      remove { }
     105    }
     106
    97107    [field: NonSerialized]
    98108    public event CollectionItemsChangedEventHandler<T> ItemsAdded;
    99109    protected virtual void OnItemsAdded(IEnumerable<T> items) {
    100       if (ItemsAdded != null)
    101         ItemsAdded(this, new CollectionItemsChangedEventArgs<T>(items));
     110      CollectionItemsChangedEventHandler<T> handler = ItemsAdded;
     111      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    102112    }
    103113
     
    105115    public event CollectionItemsChangedEventHandler<T> ItemsRemoved;
    106116    protected virtual void OnItemsRemoved(IEnumerable<T> items) {
    107       if (ItemsRemoved != null)
    108         ItemsRemoved(this, new CollectionItemsChangedEventArgs<T>(items));
     117      CollectionItemsChangedEventHandler<T> handler = ItemsRemoved;
     118      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    109119    }
    110120
     
    112122    public event CollectionItemsChangedEventHandler<T> CollectionReset;
    113123    protected virtual void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) {
    114       if (CollectionReset != null)
    115         CollectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
     124      CollectionItemsChangedEventHandler<T> handler = CollectionReset;
     125      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
    116126    }
    117127
     
    119129    public event PropertyChangedEventHandler PropertyChanged;
    120130    protected virtual void OnPropertyChanged(string propertyName) {
    121       if (PropertyChanged != null)
    122         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     131      PropertyChangedEventHandler handler = PropertyChanged;
     132      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    123133    }
    124134
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableDictionary.cs

    r3019 r3317  
    3434
    3535    #region Properties
     36    public bool ReadOnlyView {
     37      get { return true; }
     38      set { throw new NotSupportedException(); }
     39    }
     40
    3641    public ICollection<TKey> Keys {
    3742      get { return dict.Keys; }
     
    123128    }
    124129
     130    event EventHandler IObservableCollection<KeyValuePair<TKey, TValue>>.ReadOnlyViewChanged {
     131      add { }
     132      remove { }
     133    }
     134
    125135    [field: NonSerialized]
    126136    public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsAdded;
    127137    protected virtual void OnItemsAdded(IEnumerable<KeyValuePair<TKey, TValue>> items) {
    128       if (ItemsAdded != null)
    129         ItemsAdded(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items));
     138      CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> handler = ItemsAdded;
     139      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items));
    130140    }
    131141
     
    133143    public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsRemoved;
    134144    protected virtual void OnItemsRemoved(IEnumerable<KeyValuePair<TKey, TValue>> items) {
    135       if (ItemsRemoved != null)
    136         ItemsRemoved(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items));
     145      CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> handler = ItemsRemoved;
     146      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items));
    137147    }
    138148
     
    140150    public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsReplaced;
    141151    protected virtual void OnItemsReplaced(IEnumerable<KeyValuePair<TKey, TValue>> items, IEnumerable<KeyValuePair<TKey, TValue>> oldItems) {
    142       if (ItemsReplaced != null)
    143         ItemsReplaced(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems));
     152      CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> handler = ItemsReplaced;
     153      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems));
    144154    }
    145155
     
    147157    public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> CollectionReset;
    148158    protected virtual void OnCollectionReset(IEnumerable<KeyValuePair<TKey, TValue>> items, IEnumerable<KeyValuePair<TKey, TValue>> oldItems) {
    149       if (CollectionReset != null)
    150         CollectionReset(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems));
     159      CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> handler = CollectionReset;
     160      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems));
    151161    }
    152162
     
    154164    public event PropertyChangedEventHandler PropertyChanged;
    155165    protected virtual void OnPropertyChanged(string propertyName) {
    156       if (PropertyChanged != null)
    157         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     166      PropertyChangedEventHandler handler = PropertyChanged;
     167      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    158168    }
    159169
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableKeyedCollection.cs

    r3019 r3317  
    3434
    3535    #region Properties
     36    public bool ReadOnlyView {
     37      get { return true; }
     38      set { throw new NotSupportedException(); }
     39    }
     40
    3641    public int Count {
    3742      get { return collection.Count; }
     
    112117    }
    113118
     119    event EventHandler IObservableCollection<TItem>.ReadOnlyViewChanged {
     120      add { }
     121      remove { }
     122    }
     123
    114124    [field: NonSerialized]
    115125    public event CollectionItemsChangedEventHandler<TItem> ItemsAdded;
    116126    protected virtual void OnItemsAdded(IEnumerable<TItem> items) {
    117       if (ItemsAdded != null)
    118         ItemsAdded(this, new CollectionItemsChangedEventArgs<TItem>(items));
     127      CollectionItemsChangedEventHandler<TItem> handler = ItemsAdded;
     128      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<TItem>(items));
    119129    }
    120130
     
    122132    public event CollectionItemsChangedEventHandler<TItem> ItemsRemoved;
    123133    protected virtual void OnItemsRemoved(IEnumerable<TItem> items) {
    124       if (ItemsRemoved != null)
    125         ItemsRemoved(this, new CollectionItemsChangedEventArgs<TItem>(items));
     134      CollectionItemsChangedEventHandler<TItem> handler = ItemsRemoved;
     135      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<TItem>(items));
    126136    }
    127137
     
    129139    public event CollectionItemsChangedEventHandler<TItem> ItemsReplaced;
    130140    protected virtual void OnItemsReplaced(IEnumerable<TItem> items, IEnumerable<TItem> oldItems) {
    131       if (ItemsReplaced != null)
    132         ItemsReplaced(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems));
     141      CollectionItemsChangedEventHandler<TItem> handler = ItemsReplaced;
     142      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems));
    133143    }
    134144
     
    136146    public event CollectionItemsChangedEventHandler<TItem> CollectionReset;
    137147    protected virtual void OnCollectionReset(IEnumerable<TItem> items, IEnumerable<TItem> oldItems) {
    138       if (CollectionReset != null)
    139         CollectionReset(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems));
     148      CollectionItemsChangedEventHandler<TItem> handler = CollectionReset;
     149      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems));
    140150    }
    141151
     
    143153    public event PropertyChangedEventHandler PropertyChanged;
    144154    protected virtual void OnPropertyChanged(string propertyName) {
    145       if (PropertyChanged != null)
    146         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     155      PropertyChangedEventHandler handler = PropertyChanged;
     156      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    147157    }
    148158
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableList.cs

    r3019 r3317  
    3434
    3535    #region Properties
     36    public bool ReadOnlyView {
     37      get { return true; }
     38      set { throw new NotSupportedException(); }
     39    }
     40
    3641    public int Count {
    3742      get { return ((ICollection<T>)list).Count; }
     
    119124    }
    120125
     126    event EventHandler IObservableCollection<T>.ReadOnlyViewChanged {
     127      add { }
     128      remove { }
     129    }
     130
    121131    [field: NonSerialized]
    122132    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsAdded;
    123133    protected virtual void OnItemsAdded(IEnumerable<IndexedItem<T>> items) {
    124       if (ItemsAdded != null)
    125         ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items));
     134      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsAdded;
     135      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items));
    126136    }
    127137
     
    133143    }
    134144    private void OnItemsAdded(IEnumerable<T> items) {
    135       if (itemsAdded != null)
    136         itemsAdded(this, new CollectionItemsChangedEventArgs<T>(items));
     145      CollectionItemsChangedEventHandler<T> handler = itemsAdded;
     146      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    137147    }
    138148
     
    140150    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved;
    141151    protected virtual void OnItemsRemoved(IEnumerable<IndexedItem<T>> items) {
    142       if (ItemsRemoved != null)
    143         ItemsRemoved(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items));
     152      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsRemoved;
     153      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items));
    144154    }
    145155
     
    151161    }
    152162    private void OnItemsRemoved(IEnumerable<T> items) {
    153       if (itemsRemoved != null)
    154         itemsRemoved(this, new CollectionItemsChangedEventArgs<T>(items));
     163      CollectionItemsChangedEventHandler<T> handler = itemsRemoved;
     164      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    155165    }
    156166
     
    158168    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced;
    159169    protected virtual void OnItemsReplaced(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    160       if (ItemsReplaced != null)
    161         ItemsReplaced(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     170      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsReplaced;
     171      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    162172    }
    163173
     
    165175    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsMoved;
    166176    protected virtual void OnItemsMoved(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    167       if (ItemsMoved != null)
    168         ItemsMoved(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     177      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsMoved;
     178      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    169179    }
    170180
     
    172182    public event CollectionItemsChangedEventHandler<IndexedItem<T>> CollectionReset;
    173183    protected virtual void OnCollectionReset(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    174       if (CollectionReset != null)
    175         CollectionReset(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
     184      CollectionItemsChangedEventHandler<IndexedItem<T>> handler = CollectionReset;
     185      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));
    176186    }
    177187
     
    183193    }
    184194    private void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) {
    185       if (collectionReset != null)
    186         collectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
     195      CollectionItemsChangedEventHandler<T> handler = collectionReset;
     196      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
    187197    }
    188198
     
    190200    public event PropertyChangedEventHandler PropertyChanged;
    191201    protected virtual void OnPropertyChanged(string propertyName) {
    192       if (PropertyChanged != null)
    193         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     202      PropertyChangedEventHandler handler = PropertyChanged;
     203      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    194204    }
    195205
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableSet.cs

    r3019 r3317  
    3434
    3535    #region Properties
     36    public bool ReadOnlyView {
     37      get { return true; }
     38      set { throw new NotSupportedException(); }
     39    }
     40
    3641    public int Count {
    3742      get { return set.Count; }
     
    136141    }
    137142
     143    event EventHandler IObservableCollection<T>.ReadOnlyViewChanged {
     144      add { }
     145      remove { }
     146    }
     147
    138148    [field: NonSerialized]
    139149    public event CollectionItemsChangedEventHandler<T> ItemsAdded;
    140150    protected virtual void OnItemsAdded(IEnumerable<T> items) {
    141       if (ItemsAdded != null)
    142         ItemsAdded(this, new CollectionItemsChangedEventArgs<T>(items));
     151      CollectionItemsChangedEventHandler<T> handler = ItemsAdded;
     152      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    143153    }
    144154
     
    146156    public event CollectionItemsChangedEventHandler<T> ItemsRemoved;
    147157    protected virtual void OnItemsRemoved(IEnumerable<T> items) {
    148       if (ItemsRemoved != null)
    149         ItemsRemoved(this, new CollectionItemsChangedEventArgs<T>(items));
     158      CollectionItemsChangedEventHandler<T> handler = ItemsRemoved;
     159      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));
    150160    }
    151161
     
    153163    public event CollectionItemsChangedEventHandler<T> CollectionReset;
    154164    protected virtual void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) {
    155       if (CollectionReset != null)
    156         CollectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
     165      CollectionItemsChangedEventHandler<T> handler = CollectionReset;
     166      if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
    157167    }
    158168
     
    160170    public event PropertyChangedEventHandler PropertyChanged;
    161171    protected virtual void OnPropertyChanged(string propertyName) {
    162       if (PropertyChanged != null)
    163         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     172      PropertyChangedEventHandler handler = PropertyChanged;
     173      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    164174    }
    165175
Note: See TracChangeset for help on using the changeset viewer.