Changeset 9657 for trunk/sources/HeuristicLab.Data/3.3/ValueTypeArray.cs
- Timestamp:
- 06/25/13 10:43:27 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Data/3.3/ValueTypeArray.cs
r9456 r9657 43 43 protected T[] array; 44 44 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("An element name must be specified for each element."); 55 else 56 elementNames = new List<string>(value); 57 OnElementNamesChanged(); 58 } 59 } 60 45 61 public virtual int Length { 46 62 get { return array.Length; } … … 51 67 if (value != Length) { 52 68 Array.Resize<T>(ref array, value); 69 while (elementNames.Count > value) 70 elementNames.RemoveAt(elementNames.Count - 1); 71 while (elementNames.Count < value) 72 elementNames.Add("Element " + elementNames.Count); 73 OnElementNamesChanged(); 53 74 OnReset(); 54 75 } … … 73 94 } 74 95 96 [StorableHook(HookType.AfterDeserialization)] 97 private void AfterDeserialization() { 98 if (elementNames == null) { elementNames = new List<string>(); } 99 } 100 75 101 [StorableConstructor] 76 102 protected ValueTypeArray(bool deserializing) : base(deserializing) { } … … 79 105 this.array = (T[])original.array.Clone(); 80 106 this.readOnly = original.readOnly; 107 this.elementNames = new List<string>(original.elementNames); 81 108 } 82 109 protected ValueTypeArray() { 83 110 array = new T[0]; 84 111 readOnly = false; 112 elementNames = new List<string>(); 85 113 } 86 114 protected ValueTypeArray(int length) { 87 115 array = new T[length]; 88 116 readOnly = false; 117 elementNames = new List<string>(); 89 118 } 90 119 protected ValueTypeArray(T[] elements) { … … 92 121 array = (T[])elements.Clone(); 93 122 readOnly = false; 123 elementNames = new List<string>(); 94 124 } 95 125 … … 125 155 } 126 156 157 public event EventHandler ElementNamesChanged; 158 protected virtual void OnElementNamesChanged() { 159 EventHandler handler = ElementNamesChanged; 160 if (handler != null) 161 handler(this, EventArgs.Empty); 162 } 163 127 164 public event EventHandler<EventArgs<int>> ItemChanged; 128 165 protected virtual void OnItemChanged(int index) {
Note: See TracChangeset
for help on using the changeset viewer.