Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/10 03:07:12 (15 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • replaced Changed in IItem by ToStringChanged
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/ItemList.cs

    r2833 r2932  
    3636  [Item("ItemList<T>", "Represents a list of items.")]
    3737  public class ItemList<T> : ObservableList<T>, IItem where T : class, IItem {
    38     [Storable(Name = "RestoreEvents")]
    39     private object RestoreEvents {
    40       get { return null; }
    41       set {
    42         foreach (T item in this)
    43           if (item != null) item.Changed += new ChangedEventHandler(Item_Changed);
    44       }
    45     }
    46 
    4738    public virtual string ItemName {
    4839      get { return ItemAttribute.GetName(this.GetType()); }
     
    5748    public ItemList() : base() { }
    5849    public ItemList(int capacity) : base(capacity) { }
    59     public ItemList(IEnumerable<T> collection) : base(collection) {
    60       foreach (T item in this)
    61         if (item != null) item.Changed += new ChangedEventHandler(Item_Changed);
    62     }
     50    public ItemList(IEnumerable<T> collection) : base(collection) { }
    6351
    6452    public object Clone() {
     
    7664    }
    7765
    78     public event ChangedEventHandler Changed;
    79     protected void OnChanged() {
    80       OnChanged(new ChangedEventArgs());
    81     }
    82     protected virtual void OnChanged(ChangedEventArgs e) {
    83       if ((e.RegisterChangedObject(this)) && (Changed != null))
    84         Changed(this, e);
    85     }
    86 
    87     protected override void OnItemsAdded(IEnumerable<IndexedItem<T>> items) {
    88       foreach (IndexedItem<T> item in items)
    89         if (item.Value != null) item.Value.Changed += new ChangedEventHandler(Item_Changed);
    90       base.OnItemsAdded(items);
    91     }
    92     protected override void OnItemsRemoved(IEnumerable<IndexedItem<T>> items) {
    93       foreach (IndexedItem<T> item in items)
    94         if (item.Value != null) item.Value.Changed -= new ChangedEventHandler(Item_Changed);
    95       base.OnItemsRemoved(items);
    96     }
    97     protected override void OnItemsReplaced(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    98       foreach (IndexedItem<T> oldItem in oldItems)
    99         if (oldItem.Value != null) oldItem.Value.Changed -= new ChangedEventHandler(Item_Changed);
    100       foreach (IndexedItem<T> item in items)
    101         if (item.Value != null) item.Value.Changed += new ChangedEventHandler(Item_Changed);
    102       base.OnItemsReplaced(items, oldItems);
    103     }
    104     protected override void OnCollectionReset(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {
    105       foreach (IndexedItem<T> oldItem in oldItems)
    106         if (oldItem.Value != null) oldItem.Value.Changed -= new ChangedEventHandler(Item_Changed);
    107       foreach (IndexedItem<T> item in items)
    108         if (item.Value != null) item.Value.Changed += new ChangedEventHandler(Item_Changed);
    109       base.OnCollectionReset(items, oldItems);
    110     }
    111     protected override void OnPropertyChanged(string propertyName) {
    112       base.OnPropertyChanged(propertyName);
    113       OnChanged();
    114     }
    115 
    116     private void Item_Changed(object sender, ChangedEventArgs e) {
    117       OnChanged(e);
     66    public event EventHandler ToStringChanged;
     67    protected virtual void OnToStringChanged() {
     68      if (ToStringChanged != null)
     69        ToStringChanged(this, EventArgs.Empty);
    11870    }
    11971  }
Note: See TracChangeset for help on using the changeset viewer.