Changeset 14056 for trunk/sources
- Timestamp:
- 07/13/16 09:47:55 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs
r14037 r14056 135 135 136 136 while (currentExecutionContext != null) { 137 valueParam = currentExecutionContext.Parameters[translatedName] as IValueParameter; 138 lookupParam = currentExecutionContext.Parameters[translatedName] as ILookupParameter; 137 IParameter param = null; 138 while (currentExecutionContext != null && !currentExecutionContext.Parameters.TryGetValue(translatedName, out param)) 139 currentExecutionContext = currentExecutionContext.Parent; 140 if (currentExecutionContext == null) break; 141 142 valueParam = param as IValueParameter; 143 lookupParam = param as ILookupParameter; 139 144 140 145 if ((valueParam == null) && (lookupParam == null)) … … 148 153 else if (lookupParam == null) return valueParam; 149 154 } 150 if (lookupParam != null)translatedName = lookupParam.ActualName;155 translatedName = lookupParam.ActualName; 151 156 152 157 currentExecutionContext = currentExecutionContext.Parent; 153 while ((currentExecutionContext != null) && !currentExecutionContext.Parameters.ContainsKey(translatedName))154 currentExecutionContext = currentExecutionContext.Parent;155 158 } 156 159 return null; 157 160 } 158 161 protected static IVariable LookupVariable(IScope scope, string name) { 159 while ((scope != null) && !scope.Variables.ContainsKey(name)) 162 IVariable variable = null; 163 while (scope != null && !scope.Variables.TryGetValue(name, out variable)) 160 164 scope = scope.Parent; 161 return scope != null ? scope.Variables[name]: null;165 return scope != null ? variable : null; 162 166 } 163 167 … … 171 175 } 172 176 173 protected static IItem GetValue(IExecutionContext executionContext, ref string name ) {177 protected static IItem GetValue(IExecutionContext executionContext, ref string name, bool verifyType = true) { 174 178 // try to get value from context stack 175 179 IValueParameter param = GetValueParameterAndTranslateName(executionContext, ref name); … … 179 183 IVariable var = LookupVariable(executionContext.Scope, name); 180 184 if (var != null) { 181 if ( !(var.Value is T))185 if (verifyType && !(var.Value is T)) 182 186 throw new InvalidOperationException( 183 187 string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".",
Note: See TracChangeset
for help on using the changeset viewer.