Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/10 02:27:02 (14 years ago)
Author:
swagner
Message:

Refactored HeuristicLab.Collections (#977)

Location:
trunk/sources/HeuristicLab.Core/3.3/Collections
Files:
1 added
1 moved

Legend:

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

    r3381 r3390  
    3535  [StorableClass]
    3636  [Item("ItemList<T>", "Represents a list of items.")]
    37   public class ItemList<T> : ObservableList<T>, IItem where T : class, IItem {
     37  public class ItemList<T> : ObservableList<T>, IItemList<T> where T : class, IItem {
    3838    public virtual string ItemName {
    3939      get { return ItemAttribute.GetName(this.GetType()); }
     
    4646    }
    4747
    48     public ItemList() : base() { }
    49     public ItemList(int capacity) : base(capacity) { }
    50     public ItemList(IEnumerable<T> collection) : base(collection) { }
     48    [Storable]
     49    private List<T> Items {
     50      get { return list; }
     51      set { list = value; }
     52    }
     53
     54    [Storable]
     55    private bool readOnlyView;
     56    public virtual bool ReadOnlyView {
     57      get { return readOnlyView; }
     58      set {
     59        if ((readOnlyView != value) && !((ICollection<T>)list).IsReadOnly) {
     60          readOnlyView = value;
     61          OnReadOnlyViewChanged();
     62          OnPropertyChanged("ReadOnlyView");
     63        }
     64      }
     65    }
     66
     67    public ItemList()
     68      : base() {
     69      readOnlyView = ((ICollection<T>)list).IsReadOnly;
     70    }
     71    public ItemList(int capacity)
     72      : base(capacity) {
     73      readOnlyView = ((ICollection<T>)list).IsReadOnly;
     74    }
     75    public ItemList(IEnumerable<T> collection)
     76      : base(collection) {
     77      readOnlyView = ((ICollection<T>)list).IsReadOnly;
     78    }
     79    [StorableConstructor]
     80    protected ItemList(bool deserializing) { }
    5181
    5282    public object Clone() {
    5383      return Clone(new Cloner());
    5484    }
    55 
    5685    public virtual IDeepCloneable Clone(Cloner cloner) {
    5786      ItemList<T> clone = (ItemList<T>)Activator.CreateInstance(this.GetType());
    5887      cloner.RegisterClonedObject(this, clone);
    59       clone.ReadOnlyView = ReadOnlyView;
     88      clone.readOnlyView = readOnlyView;
    6089      clone.list = new List<T>(this.Select(x => (T)cloner.Clone(x)));
    6190      return clone;
     91    }
     92
     93    public new ReadOnlyItemList<T> AsReadOnly() {
     94      return new ReadOnlyItemList<T>(this);
    6295    }
    6396
     
    76109      if (handler != null) handler(this, EventArgs.Empty);
    77110    }
     111    public event EventHandler ReadOnlyViewChanged;
     112    protected virtual void OnReadOnlyViewChanged() {
     113      EventHandler handler = ReadOnlyViewChanged;
     114      if (handler != null) handler(this, EventArgs.Empty);
     115    }
    78116  }
    79117}
Note: See TracChangeset for help on using the changeset viewer.