Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/14/10 18:26:23 (15 years ago)
Author:
swagner
Message:

Restructured persistence code of read-only observable collections (#548)

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

Legend:

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

    r3017 r3019  
    3333    private IObservableArray<T> array;
    3434
    35     #region Persistence
    36     private ReadOnlyObservableArray() { }
    37 
    38     [StorableHook(HookType.AfterDeserialization)]
    39     private void PostDeserializationHook() {
    40       RegisterEvents();
    41     }
    42     #endregion
    43 
    4435    #region Properties
    4536    public int Length {
     
    6253    #endregion
    6354
    64    
    65 
    6655    #region Constructors
     56    protected ReadOnlyObservableArray() { }
    6757    public ReadOnlyObservableArray(IObservableArray<T> array) {
    6858      if (array == null) throw new ArgumentNullException();
    6959      this.array = array;
    7060      RegisterEvents();
    71     }
    72 
    73     private void RegisterEvents() {
    74       array.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>(array_ItemsReplaced);
    75       array.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(array_ItemsMoved);
    76       array.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(array_CollectionReset);
    77       array.PropertyChanged += new PropertyChangedEventHandler(array_PropertyChanged);
    7861    }
    7962    #endregion
     
    126109
    127110    #region Events
     111    [StorableHook(HookType.AfterDeserialization)]
     112    protected void RegisterEvents() {
     113      array.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>(array_ItemsReplaced);
     114      array.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(array_ItemsMoved);
     115      array.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(array_CollectionReset);
     116      array.PropertyChanged += new PropertyChangedEventHandler(array_PropertyChanged);
     117    }
     118
    128119    [field: NonSerialized]
    129120    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced;
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableCollection.cs

    r3017 r3019  
    3333    private IObservableCollection<T> collection;
    3434
    35     #region persistence
    36     private ReadOnlyObservableCollection() { }
    37 
    38     [StorableHook(HookType.AfterDeserialization)]
    39     private void PostDeserializationHook() {
    40       RegisterEvents();
    41     }
    42     #endregion
    43 
    4435    #region Properties
    4536    public int Count {
     
    5243
    5344    #region Constructors
     45    protected ReadOnlyObservableCollection() { }
    5446    public ReadOnlyObservableCollection(IObservableCollection<T> collection) {
    5547      if (collection == null) throw new ArgumentNullException();
    5648      this.collection = collection;
    5749      RegisterEvents();
    58     }
    59 
    60     private void RegisterEvents() {
    61       collection.ItemsAdded += new CollectionItemsChangedEventHandler<T>(collection_ItemsAdded);
    62       collection.ItemsRemoved += new CollectionItemsChangedEventHandler<T>(collection_ItemsRemoved);
    63       collection.CollectionReset += new CollectionItemsChangedEventHandler<T>(collection_CollectionReset);
    64       collection.PropertyChanged += new PropertyChangedEventHandler(collection_PropertyChanged);
    6550    }
    6651    #endregion
     
    10287
    10388    #region Events
     89    [StorableHook(HookType.AfterDeserialization)]
     90    protected void RegisterEvents() {
     91      collection.ItemsAdded += new CollectionItemsChangedEventHandler<T>(collection_ItemsAdded);
     92      collection.ItemsRemoved += new CollectionItemsChangedEventHandler<T>(collection_ItemsRemoved);
     93      collection.CollectionReset += new CollectionItemsChangedEventHandler<T>(collection_CollectionReset);
     94      collection.PropertyChanged += new PropertyChangedEventHandler(collection_PropertyChanged);
     95    }
     96
    10497    [field: NonSerialized]
    10598    public event CollectionItemsChangedEventHandler<T> ItemsAdded;
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableDictionary.cs

    r3017 r3019  
    3333    private IObservableDictionary<TKey, TValue> dict;
    3434
    35     #region persistence
    36     private ReadOnlyObservableDictionary() { }
    37 
    38     [StorableHook(HookType.AfterDeserialization)]
    39     private void PostDeserizlationHook() {
    40       RegisterEvents();
    41     }
    42     #endregion
    43 
    4435    #region Properties
    4536    public ICollection<TKey> Keys {
     
    6657
    6758    #region Constructors
     59    protected ReadOnlyObservableDictionary() { }
    6860    public ReadOnlyObservableDictionary(IObservableDictionary<TKey, TValue> dictionary) {
    6961      if (dictionary == null) throw new ArgumentNullException();
    7062      dict = dictionary;
    7163      RegisterEvents();
    72     }
    73 
    74     private void RegisterEvents() {
    75       dict.ItemsAdded += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_ItemsAdded);
    76       dict.ItemsRemoved += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_ItemsRemoved);
    77       dict.ItemsReplaced += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_ItemsReplaced);
    78       dict.CollectionReset += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_CollectionReset);
    79       dict.PropertyChanged += new PropertyChangedEventHandler(dict_PropertyChanged);
    8064    }
    8165    #endregion
     
    130114
    131115    #region Events
     116    [StorableHook(HookType.AfterDeserialization)]
     117    protected void RegisterEvents() {
     118      dict.ItemsAdded += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_ItemsAdded);
     119      dict.ItemsRemoved += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_ItemsRemoved);
     120      dict.ItemsReplaced += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_ItemsReplaced);
     121      dict.CollectionReset += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_CollectionReset);
     122      dict.PropertyChanged += new PropertyChangedEventHandler(dict_PropertyChanged);
     123    }
     124
    132125    [field: NonSerialized]
    133126    public event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsAdded;
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableKeyedCollection.cs

    r3017 r3019  
    3333    private IObservableKeyedCollection<TKey, TItem> collection;
    3434
    35     #region persistence
    36     private ReadOnlyObservableKeyedCollection() { }
    37 
    38     [StorableHook(HookType.AfterDeserialization)]
    39     private void PostDeserizlationHook() {
    40       RegisterEvents();
    41     }
    42     #endregion
    43 
    4435    #region Properties
    4536    public int Count {
     
    5849
    5950    #region Constructors
     51    protected ReadOnlyObservableKeyedCollection() { }
    6052    public ReadOnlyObservableKeyedCollection(IObservableKeyedCollection<TKey, TItem> collection) {
    6153      if (collection == null) throw new ArgumentNullException();
    6254      this.collection = collection;
    6355      RegisterEvents();
    64     }
    65 
    66     private void RegisterEvents() {
    67       collection.ItemsAdded += new CollectionItemsChangedEventHandler<TItem>(collection_ItemsAdded);
    68       collection.ItemsRemoved += new CollectionItemsChangedEventHandler<TItem>(collection_ItemsRemoved);
    69       collection.ItemsReplaced += new CollectionItemsChangedEventHandler<TItem>(collection_ItemsReplaced);
    70       collection.CollectionReset += new CollectionItemsChangedEventHandler<TItem>(collection_CollectionReset);
    71       collection.PropertyChanged += new PropertyChangedEventHandler(collection_PropertyChanged);
    7256    }
    7357    #endregion
     
    119103
    120104    #region Events
     105    [StorableHook(HookType.AfterDeserialization)]
     106    protected void RegisterEvents() {
     107      collection.ItemsAdded += new CollectionItemsChangedEventHandler<TItem>(collection_ItemsAdded);
     108      collection.ItemsRemoved += new CollectionItemsChangedEventHandler<TItem>(collection_ItemsRemoved);
     109      collection.ItemsReplaced += new CollectionItemsChangedEventHandler<TItem>(collection_ItemsReplaced);
     110      collection.CollectionReset += new CollectionItemsChangedEventHandler<TItem>(collection_CollectionReset);
     111      collection.PropertyChanged += new PropertyChangedEventHandler(collection_PropertyChanged);
     112    }
     113
    121114    [field: NonSerialized]
    122115    public event CollectionItemsChangedEventHandler<TItem> ItemsAdded;
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableList.cs

    r3017 r3019  
    3333    private IObservableList<T> list;
    3434
    35     #region persistence
    36     private ReadOnlyObservableList() { }
    37 
    38     [StorableHook(HookType.AfterDeserialization)]
    39     private void PostDeserizlationHook() {
    40       RegisterEvents();
    41     }
    42     #endregion
    43 
    4435    #region Properties
    4536    public int Count {
     
    6051
    6152    #region Constructors
     53    protected ReadOnlyObservableList() { }
    6254    public ReadOnlyObservableList(IObservableList<T> list) {
    6355      if (list == null) throw new ArgumentNullException();
     
    6557      RegisterEvents();
    6658    }
    67 
    68     private void RegisterEvents() {
     59    #endregion
     60
     61    #region Access
     62    public bool Contains(T item) {
     63      return list.Contains(item);
     64    }
     65
     66    public int IndexOf(T item) {
     67      return list.IndexOf(item);
     68    }
     69    #endregion
     70
     71    #region Manipulation
     72    void ICollection<T>.Add(T item) {
     73      throw new NotSupportedException();
     74    }
     75
     76    void IList<T>.Insert(int index, T item) {
     77      throw new NotSupportedException();
     78    }
     79
     80    bool ICollection<T>.Remove(T item) {
     81      throw new NotSupportedException();
     82    }
     83    void IList<T>.RemoveAt(int index) {
     84      throw new NotSupportedException();
     85    }
     86
     87    void ICollection<T>.Clear() {
     88      throw new NotSupportedException();
     89    }
     90    #endregion
     91
     92    #region Conversion
     93    public void CopyTo(T[] array, int arrayIndex) {
     94      list.CopyTo(array, arrayIndex);
     95    }
     96    #endregion
     97
     98    #region Enumeration
     99    public IEnumerator<T> GetEnumerator() {
     100      return ((ICollection<T>)list).GetEnumerator();
     101    }
     102    IEnumerator IEnumerable.GetEnumerator() {
     103      return ((IEnumerable)list).GetEnumerator();
     104    }
     105    #endregion
     106
     107    #region Events
     108    [StorableHook(HookType.AfterDeserialization)]
     109    protected void RegisterEvents() {
    69110      list.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsAdded);
    70111      ((IObservableCollection<T>)list).ItemsAdded += new CollectionItemsChangedEventHandler<T>(list_ItemsAdded);
     
    77118      list.PropertyChanged += new PropertyChangedEventHandler(list_PropertyChanged);
    78119    }
    79     #endregion
    80 
    81     #region Access
    82     public bool Contains(T item) {
    83       return list.Contains(item);
    84     }
    85 
    86     public int IndexOf(T item) {
    87       return list.IndexOf(item);
    88     }
    89     #endregion
    90 
    91     #region Manipulation
    92     void ICollection<T>.Add(T item) {
    93       throw new NotSupportedException();
    94     }
    95 
    96     void IList<T>.Insert(int index, T item) {
    97       throw new NotSupportedException();
    98     }
    99 
    100     bool ICollection<T>.Remove(T item) {
    101       throw new NotSupportedException();
    102     }
    103     void IList<T>.RemoveAt(int index) {
    104       throw new NotSupportedException();
    105     }
    106 
    107     void ICollection<T>.Clear() {
    108       throw new NotSupportedException();
    109     }
    110     #endregion
    111 
    112     #region Conversion
    113     public void CopyTo(T[] array, int arrayIndex) {
    114       list.CopyTo(array, arrayIndex);
    115     }
    116     #endregion
    117 
    118     #region Enumeration
    119     public IEnumerator<T> GetEnumerator() {
    120       return ((ICollection<T>)list).GetEnumerator();
    121     }
    122     IEnumerator IEnumerable.GetEnumerator() {
    123       return ((IEnumerable)list).GetEnumerator();
    124     }
    125     #endregion
    126 
    127     #region Events
     120
    128121    [field: NonSerialized]
    129122    public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsAdded;
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableSet.cs

    r3017 r3019  
    3333    private IObservableSet<T> set;
    3434
    35     #region persistence
    36     private ReadOnlyObservableSet() { }
    37 
    38     [StorableHook(HookType.AfterDeserialization)]
    39     private void PostDeserizlationHook() {
    40       RegisterEvents();
    41     }
    42     #endregion
    43 
    4435    #region Properties
    4536    public int Count {
     
    5243
    5344    #region Constructors
     45    protected ReadOnlyObservableSet() { }
    5446    public ReadOnlyObservableSet(IObservableSet<T> set) {
    5547      if (set == null) throw new ArgumentNullException();
    5648      this.set = set;
    5749      RegisterEvents();
    58     }
    59 
    60     private void RegisterEvents() {
    61       set.ItemsAdded += new CollectionItemsChangedEventHandler<T>(set_ItemsAdded);
    62       set.ItemsRemoved += new CollectionItemsChangedEventHandler<T>(set_ItemsRemoved);
    63       set.CollectionReset += new CollectionItemsChangedEventHandler<T>(set_CollectionReset);
    64       set.PropertyChanged += new PropertyChangedEventHandler(set_PropertyChanged);
    6550    }
    6651    #endregion
     
    143128
    144129    #region Events
     130    [StorableHook(HookType.AfterDeserialization)]
     131    protected void RegisterEvents() {
     132      set.ItemsAdded += new CollectionItemsChangedEventHandler<T>(set_ItemsAdded);
     133      set.ItemsRemoved += new CollectionItemsChangedEventHandler<T>(set_ItemsRemoved);
     134      set.CollectionReset += new CollectionItemsChangedEventHandler<T>(set_CollectionReset);
     135      set.PropertyChanged += new PropertyChangedEventHandler(set_PropertyChanged);
     136    }
     137
    145138    [field: NonSerialized]
    146139    public event CollectionItemsChangedEventHandler<T> ItemsAdded;
Note: See TracChangeset for help on using the changeset viewer.