Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/23/13 15:12:10 (11 years ago)
Author:
mkommend
Message:

#2075: Integrated the performed changes in the stable branch.

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Data/3.3/ValueTypeArray.cs

    r9456 r9737  
    4343    protected T[] array;
    4444
     45    [Storable]
     46    protected List<string> elementNames;
     47    public virtual IEnumerable<string> ElementNames {
     48      get { return this.elementNames; }
     49      set {
     50        if (ReadOnly) throw new NotSupportedException("ElementNames cannot be set. ValueTypeArray is read-only.");
     51        if (value == null || !value.Any())
     52          elementNames = new List<string>();
     53        else if (value.Count() > Length)
     54          throw new ArgumentException("The number of element names must not exceed the array length.");
     55        else
     56          elementNames = new List<string>(value);
     57        OnElementNamesChanged();
     58      }
     59    }
     60
    4561    public virtual int Length {
    4662      get { return array.Length; }
     
    5167        if (value != Length) {
    5268          Array.Resize<T>(ref array, value);
     69          while (elementNames.Count > value)
     70            elementNames.RemoveAt(elementNames.Count - 1);
     71          OnElementNamesChanged();
    5372          OnReset();
    5473        }
     
    7392    }
    7493
     94    [StorableHook(HookType.AfterDeserialization)]
     95    private void AfterDeserialization() {
     96      if (elementNames == null) { elementNames = new List<string>(); }
     97    }
     98
    7599    [StorableConstructor]
    76100    protected ValueTypeArray(bool deserializing) : base(deserializing) { }
     
    79103      this.array = (T[])original.array.Clone();
    80104      this.readOnly = original.readOnly;
     105      this.elementNames = new List<string>(original.elementNames);
    81106    }
    82107    protected ValueTypeArray() {
    83108      array = new T[0];
    84109      readOnly = false;
     110      elementNames = new List<string>();
    85111    }
    86112    protected ValueTypeArray(int length) {
    87113      array = new T[length];
    88114      readOnly = false;
     115      elementNames = new List<string>();
    89116    }
    90117    protected ValueTypeArray(T[] elements) {
     
    92119      array = (T[])elements.Clone();
    93120      readOnly = false;
     121      elementNames = new List<string>();
    94122    }
    95123
     
    125153    }
    126154
     155    public event EventHandler ElementNamesChanged;
     156    protected virtual void OnElementNamesChanged() {
     157      EventHandler handler = ElementNamesChanged;
     158      if (handler != null)
     159        handler(this, EventArgs.Empty);
     160    }
     161
    127162    public event EventHandler<EventArgs<int>> ItemChanged;
    128163    protected virtual void OnItemChanged(int index) {
Note: See TracChangeset for help on using the changeset viewer.