Changeset 12141 for branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
- Timestamp:
- 03/05/15 14:37:02 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
r12032 r12141 28 28 using HeuristicLab.Common; 29 29 using HeuristicLab.Core; 30 using HeuristicLab.Data; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 32 … … 33 34 [Item("ModifiableDataset", "Represents a dataset containing data that should be analyzed, which can be modified by adding or replacing variables and values.")] 34 35 [StorableClass] 35 public class ModifiableDataset : Dataset {36 public class ModifiableDataset : Dataset, IStringConvertibleMatrix { 36 37 [StorableConstructor] 37 38 private ModifiableDataset(bool deserializing) : base(deserializing) { } … … 99 100 } 100 101 101 public void ChangeVariableValue(object value, string variableName, int row) {102 public void SetVariableValue(object value, string variableName, int row) { 102 103 IList list; 103 104 variableValues.TryGetValue(variableName, out list); … … 106 107 if (row < 0 || list.Count < row) 107 108 throw new ArgumentOutOfRangeException("Invalid row value"); 109 if (GetVariableType(variableName) != value.GetType()) 110 throw new ArgumentException("The type of the provided value does not match the variable type."); 111 108 112 list[row] = value; 109 113 } … … 116 120 return list[0].GetType(); 117 121 } 122 123 bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) { 124 var variableName = variableNames[columnIndex]; 125 // if value represents a double 126 double dv; 127 if (double.TryParse(value, out dv)) { 128 SetVariableValue(dv, variableName, rowIndex); 129 return true; 130 } 131 // if value represents a DateTime object 132 DateTime dt; 133 if (DateTime.TryParse(value, out dt)) { 134 SetVariableValue(dt, variableName, rowIndex); 135 return true; 136 } 137 // if value is simply a string 138 SetVariableValue(value, variableName, rowIndex); 139 return true; 140 } 141 142 bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) { 143 return ValidateValue(value, out errorMessage); 144 } 145 146 private static bool ValidateValue(string value, out string errorMessage) { 147 double dv; 148 if (double.TryParse(value, out dv)) { 149 errorMessage = string.Empty; 150 return true; 151 } 152 DateTime dt; 153 if (DateTime.TryParse(value, out dt)) { 154 errorMessage = string.Empty; 155 return true; 156 } 157 errorMessage = "Value could not be validated. Please ensure that the value is either a string, a double, or a DateTime value."; 158 return false; 159 } 118 160 } 119 161 }
Note: See TracChangeset
for help on using the changeset viewer.