- Timestamp:
- 03/12/13 12:20:25 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/DoubleArray.cs
r7259 r9308 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using System.Text; 23 26 using HeuristicLab.Common; … … 28 31 [Item("DoubleArray", "Represents an array of double values.")] 29 32 [StorableClass] 30 public class DoubleArray : ValueTypeArray<double> , IStringConvertibleArray{33 public class DoubleArray : ValueTypeArray<double> { 31 34 [StorableConstructor] 32 35 protected DoubleArray(bool deserializing) : base(deserializing) { } … … 42 45 } 43 46 44 protected virtualbool Validate(string value, out string errorMessage) {47 protected override bool Validate(string value, out string errorMessage) { 45 48 double val; 46 49 bool valid = double.TryParse(value, out val); … … 55 58 return valid; 56 59 } 57 protected virtualstring GetValue(int index) {60 protected override string GetValue(int index) { 58 61 return this[index].ToString(); 59 62 } 60 protected virtual bool SetValue(string value, int index) { 63 protected override bool SetValue(string value, int index) { 64 if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only."); 61 65 double val; 62 66 if (double.TryParse(value, out val)) { … … 68 72 } 69 73 70 #region IStringConvertibleArray Members 71 int IStringConvertibleArray.Length { 72 get { return Length; } 73 set { Length = value; } 74 protected override bool SetValues(IEnumerable<ArrayValue<string>> arrayValues) { 75 if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only."); 76 double parsed; 77 if (!arrayValues.All(v => double.TryParse(v.Value, out parsed))) return false; 78 List<int> positions = new List<int>(); 79 foreach (var v in arrayValues) { 80 parsed = double.Parse(v.Value); 81 if (array[v.Index] != parsed) { 82 array[v.Index] = parsed; 83 positions.Add(v.Index); 84 } 85 } 86 OnItemsChanged(positions); 87 return true; 74 88 } 75 bool IStringConvertibleArray.Validate(string value, out string errorMessage) {76 return Validate(value, out errorMessage);77 }78 string IStringConvertibleArray.GetValue(int index) {79 return GetValue(index);80 }81 bool IStringConvertibleArray.SetValue(string value, int index) {82 return SetValue(value, index);83 }84 #endregion85 89 } 86 90 }
Note: See TracChangeset
for help on using the changeset viewer.