Changeset 3634 for trunk/sources/HeuristicLab.Parameters
- Timestamp:
- 05/05/10 14:28:22 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Parameters/3.3
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj
r3413 r3634 86 86 <None Include="HeuristicLabParametersPlugin.cs.frame" /> 87 87 <Compile Include="ConstrainedValueParameter.cs" /> 88 <Compile Include="SubScopesSubScopesLookupParameter.cs" /> 88 89 <Compile Include="OptionalConstrainedValueParameter.cs" /> 89 90 <Compile Include="ValueParameter.cs" /> -
trunk/sources/HeuristicLab.Parameters/3.3/SubScopesLookupParameter.cs
r3479 r3634 27 27 namespace HeuristicLab.Parameters { 28 28 /// <summary> 29 /// A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.29 /// A generic parameter representing instances of type T which are collected from or written to the sub-scopes of the current scope. 30 30 /// </summary> 31 31 [Item("SubScopesLookupParameter<T>", "A generic parameter representing instances of type T which are collected from or written to the sub-scopes of the current scope.")] -
trunk/sources/HeuristicLab.Parameters/3.3/SubScopesSubScopesLookupParameter.cs
r3626 r3634 27 27 namespace HeuristicLab.Parameters { 28 28 /// <summary> 29 /// A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.29 /// A generic parameter representing instances of type T which are collected from or written to the sub-scopes of the sub-scopes of the current scope. 30 30 /// </summary> 31 [Item("SubScopes LookupParameter<T>", "A generic parameter representing instances of type T which are collected from or written tothe sub-scopes of the current scope.")]31 [Item("SubScopesSubScopesLookupParameter<T>", "A generic parameter representing instances of type T which are collected from or written to the sub-scopes of the sub-scopes of the current scope.")] 32 32 [StorableClass] 33 public class SubScopes LookupParameter<T> : LookupParameter<ItemArray<T>> where T : class, IItem {34 public SubScopes LookupParameter() : base() { }35 public SubScopes LookupParameter(string name) : base(name) { }36 public SubScopes LookupParameter(string name, string description) : base(name, description) { }37 public SubScopes LookupParameter(string name, string description, string actualName) : base(name, description, actualName) { }33 public class SubScopesSubScopesLookupParameter<T> : LookupParameter<ItemArray<ItemArray<T>>> where T : class, IItem { 34 public SubScopesSubScopesLookupParameter() : base() { } 35 public SubScopesSubScopesLookupParameter(string name) : base(name) { } 36 public SubScopesSubScopesLookupParameter(string name, string description) : base(name, description) { } 37 public SubScopesSubScopesLookupParameter(string name, string description, string actualName) : base(name, description, actualName) { } 38 38 39 39 protected override IItem GetActualValue() { 40 string name = LookupParameter<ItemArray< T>>.TranslateName(Name, ExecutionContext);40 string name = LookupParameter<ItemArray<ItemArray<T>>>.TranslateName(Name, ExecutionContext); 41 41 IScope scope = ExecutionContext.Scope; 42 ItemArray< T> values = new ItemArray<T>(scope.SubScopes.Count);42 ItemArray<ItemArray<T>> values = new ItemArray<ItemArray<T>>(scope.SubScopes.Count); 43 43 IVariable var; 44 44 T value; 45 45 46 46 for (int i = 0; i < values.Length; i++) { 47 scope.SubScopes[i].Variables.TryGetValue(name, out var); 48 if (var != null) { 49 value = var.Value as T; 50 if ((var.Value != null) && (value == null)) 51 throw new InvalidOperationException( 52 string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".", 53 name, 54 typeof(T).GetPrettyName()) 55 ); 56 values[i] = value; 47 values[i] = new ItemArray<T>(scope.SubScopes[i].SubScopes.Count); 48 for (int j = 0; j < values[i].Length; j++) { 49 scope.SubScopes[i].SubScopes[j].Variables.TryGetValue(name, out var); 50 if (var != null) { 51 value = var.Value as T; 52 if ((var.Value != null) && (value == null)) 53 throw new InvalidOperationException( 54 string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".", 55 name, 56 typeof(T).GetPrettyName()) 57 ); 58 values[i][j] = value; 59 } 57 60 } 58 61 } … … 60 63 } 61 64 protected override void SetActualValue(IItem value) { 62 ItemArray< T> values = value as ItemArray<T>;65 ItemArray<ItemArray<T>> values = value as ItemArray<ItemArray<T>>; 63 66 if (values == null) 64 67 throw new InvalidOperationException( … … 67 70 ); 68 71 69 string name = LookupParameter<ItemArray< T>>.TranslateName(Name, ExecutionContext);72 string name = LookupParameter<ItemArray<ItemArray<T>>>.TranslateName(Name, ExecutionContext); 70 73 IScope scope = ExecutionContext.Scope; 71 74 IVariable var; 72 75 73 76 for (int i = 0; i < values.Length; i++) { 74 scope.SubScopes[i].Variables.TryGetValue(name, out var); 75 if (var != null) var.Value = values[i]; 76 else scope.SubScopes[i].Variables.Add(new Variable(name, values[i])); 77 for (int j = 0; j < values[i].Length; j++) { 78 scope.SubScopes[i].SubScopes[j].Variables.TryGetValue(name, out var); 79 if (var != null) var.Value = values[i][j]; 80 else scope.SubScopes[i].SubScopes[j].Variables.Add(new Variable(name, values[i][j])); 81 } 77 82 } 78 83 }
Note: See TracChangeset
for help on using the changeset viewer.