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/ItemArray.cs

    r3381 r3390  
    3535  [StorableClass]
    3636  [Item("ItemArray<T>", "Represents an array of items.")]
    37   public class ItemArray<T> : ObservableArray<T>, IItem where T : class, IItem {
     37  public class ItemArray<T> : ObservableArray<T>, IItemArray<T> where T : class, IItem {
    3838    public virtual string ItemName {
    3939      get { return ItemAttribute.GetName(this.GetType()); }
     
    4646    }
    4747
    48     public ItemArray() : base() { }
    49     public ItemArray(int length) : base(length) { }
    50     public ItemArray(T[] array) : base(array) { }
    51     public ItemArray(IEnumerable<T> collection) : base(collection) { }
     48    [Storable]
     49    private T[] Items {
     50      get { return array; }
     51      set { array = value; }
     52    }
     53
     54    [Storable]
     55    private bool readOnlyView;
     56    public virtual bool ReadOnlyView {
     57      get { return readOnlyView; }
     58      set {
     59        if ((readOnlyView != value) && !(array.IsReadOnly)) {
     60          readOnlyView = value;
     61          OnReadOnlyViewChanged();
     62          OnPropertyChanged("ReadOnlyView");
     63        }
     64      }
     65    }
     66
     67    public ItemArray()
     68      : base() {
     69      readOnlyView = array.IsReadOnly;
     70    }
     71    public ItemArray(int length)
     72      : base(length) {
     73      readOnlyView = array.IsReadOnly;
     74    }
     75    public ItemArray(T[] array)
     76      : base(array) {
     77      readOnlyView = array.IsReadOnly;
     78    }
     79    public ItemArray(IEnumerable<T> collection)
     80      : base(collection) {
     81      readOnlyView = array.IsReadOnly;
     82    }
     83    [StorableConstructor]
     84    protected ItemArray(bool deserializing) { }
    5285
    5386    public object Clone() {
    5487      return Clone(new Cloner());
    5588    }
    56 
    5789    public virtual IDeepCloneable Clone(Cloner cloner) {
    5890      ItemArray<T> clone = (ItemArray<T>)Activator.CreateInstance(this.GetType());
    5991      cloner.RegisterClonedObject(this, clone);
    60       clone.ReadOnlyView = ReadOnlyView;
     92      clone.readOnlyView = readOnlyView;
    6193      clone.array = this.Select(x => (T)cloner.Clone(x)).ToArray();
    6294      return clone;
     95    }
     96
     97    public new ReadOnlyItemArray<T> AsReadOnly() {
     98      return new ReadOnlyItemArray<T>(this);
    6399    }
    64100
     
    77113      if (handler != null) handler(this, EventArgs.Empty);
    78114    }
     115    public event EventHandler ReadOnlyViewChanged;
     116    protected virtual void OnReadOnlyViewChanged() {
     117      EventHandler handler = ReadOnlyViewChanged;
     118      if (handler != null) handler(this, EventArgs.Empty);
     119    }
    79120  }
    80121}
Note: See TracChangeset for help on using the changeset viewer.