Changeset 3075
- Timestamp:
- 03/16/10 23:50:46 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs
r3017 r3075 78 78 } 79 79 80 private IValueParameter Get Parameter(out string name) {81 IValueParameter valueParam = this as IValueParameter;82 ILookupParameter lookupParam = this as ILookupParameter;83 IExecutionContext current = ExecutionContext;80 private IValueParameter GetValueParameterAndTranslateName(out string actualName) { 81 IValueParameter valueParam; 82 ILookupParameter lookupParam; 83 IExecutionContext currentExecutionContext = ExecutionContext; 84 84 85 name = Name;86 while ( (valueParam != null) || (lookupParam != null)) {87 if ((valueParam != null) && (valueParam.Value != null)) return valueParam;88 if (lookupParam != null) name = lookupParam.ActualName;85 actualName = Name; 86 while (currentExecutionContext != null) { 87 valueParam = currentExecutionContext.Parameters[actualName] as IValueParameter; 88 lookupParam = currentExecutionContext.Parameters[actualName] as ILookupParameter; 89 89 90 current = current.Parent; 91 while ((current != null) && !current.Parameters.ContainsKey(name)) 92 current = current.Parent; 90 if ((valueParam == null) && (lookupParam == null)) 91 throw new InvalidOperationException( 92 string.Format("Parameter look-up chain broken. Parameter \"{0}\" is not an \"{1}\" or an \"{2}\".", 93 actualName, typeof(IValueParameter).GetPrettyName(), typeof(ILookupParameter).GetPrettyName()) 94 ); 93 95 94 if (current != null) { 95 valueParam = current.Parameters[name] as IValueParameter; 96 lookupParam = current.Parameters[name] as ILookupParameter; 97 if ((valueParam == null) && (lookupParam == null)) 98 throw new InvalidOperationException( 99 string.Format("Parameter look-up chain broken. Parameter \"{0}\" is not an \"{1}\" or an \"{2}\".", 100 name, 101 typeof(IValueParameter).GetPrettyName(), 102 typeof(ILookupParameter).GetPrettyName()) 103 ); 104 } else { 105 valueParam = null; 106 lookupParam = null; 96 if (valueParam != null) { 97 if (valueParam.Value != null) return valueParam; 98 else if (lookupParam == null) return valueParam; 107 99 } 100 if (lookupParam != null) actualName = lookupParam.ActualName; 101 102 currentExecutionContext = currentExecutionContext.Parent; 103 while ((currentExecutionContext != null) && !currentExecutionContext.Parameters.ContainsKey(actualName)) 104 currentExecutionContext = currentExecutionContext.Parent; 108 105 } 109 106 return null; … … 118 115 string name; 119 116 // try to get value from context stack 120 IValueParameter param = Get Parameter(out name);121 if (param != null ) return param.Value;117 IValueParameter param = GetValueParameterAndTranslateName(out name); 118 if (param != null && param.Value != null) return param.Value; 122 119 123 120 // try to get variable from scope … … 142 139 // try to set value in context stack 143 140 string name; 144 IValueParameter param = Get Parameter(out name);141 IValueParameter param = GetValueParameterAndTranslateName(out name); 145 142 if (param != null) { 146 143 param.Value = value;
Note: See TracChangeset
for help on using the changeset viewer.