Changeset 2805 for trunk/sources/HeuristicLab.Parameters
- Timestamp:
- 02/16/10 06:50:14 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs
r2793 r2805 111 111 return scope != null ? scope.Variables[actualName] : null; 112 112 } 113 private IValueParameter<T> GetProblemParameter(string name) { 114 IValueParameter<T> param = null; 115 if (ExecutionContext.Problem.Parameters.ContainsKey(name)) { 116 param = ExecutionContext.Problem.Parameters[name] as IValueParameter<T>; 117 if (param == null) 118 throw new InvalidOperationException( 119 string.Format("Parameter look-up chain broken. Parameter \"{0}\" is not an \"{1}\".", 120 name, 121 typeof(IValueParameter<T>).GetPrettyName()) 122 ); 123 } 124 return param; 125 } 113 126 protected override IItem GetActualValue() { 114 127 string name; 115 // try to get localvalue from context stack128 // try to get value from context stack 116 129 IValueParameter<T> param = GetParameter(out name); 117 130 if (param != null) return param.Value; 118 else { // try to get variable from scope 119 IVariable var = LookupVariable(name); 120 if (var != null) { 121 T value = var.Value as T; 122 if (value == null) 123 throw new InvalidOperationException( 124 string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".", 125 name, 126 typeof(T).GetPrettyName()) 127 ); 128 return value; 129 } 130 } 131 132 // try to get variable from scope 133 IVariable var = LookupVariable(name); 134 if (var != null) { 135 T value = var.Value as T; 136 if (value == null) 137 throw new InvalidOperationException( 138 string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".", 139 name, 140 typeof(T).GetPrettyName()) 141 ); 142 return value; 143 } 144 145 // try to get value from problem 146 IValueParameter<T> problemParam = GetProblemParameter(name); 147 if (problemParam != null) return problemParam.Value; 148 131 149 return null; 132 150 } … … 138 156 typeof(T).GetPrettyName()) 139 157 ); 140 // try to get local value fromcontext stack158 // try to set value in context stack 141 159 string name; 142 160 IValueParameter<T> param = GetParameter(out name); 143 if (param != null) param.Value = val; 144 else { // try to get variable from scope 145 IVariable var = LookupVariable(name); 146 if (var != null) var.Value = val; 147 else ExecutionContext.Scope.Variables.Add(new Variable(name, value)); 148 } 161 if (param != null) { 162 param.Value = val; 163 return; 164 } 165 166 // try to set value in scope 167 IVariable var = LookupVariable(name); 168 if (var != null) { 169 var.Value = val; 170 return; 171 } 172 173 // try to set value in problem 174 IValueParameter<T> problemParam = GetProblemParameter(name); 175 if (problemParam != null) { 176 problemParam.Value = val; 177 return; 178 } 179 180 // create new variable 181 ExecutionContext.Scope.Variables.Add(new Variable(name, value)); 149 182 } 150 183
Note: See TracChangeset
for help on using the changeset viewer.