Changeset 2757 for trunk/sources/HeuristicLab.Parameters
- Timestamp:
- 02/08/10 03:43:36 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Parameters/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs
r2756 r2757 32 32 /// A parameter whose value is retrieved from the scope. 33 33 /// </summary> 34 [Item("LookupParameter<T>", "A parameter whose value is retrieved from thescope.")]34 [Item("LookupParameter<T>", "A parameter whose value is retrieved from or written to a scope.")] 35 35 public class LookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem { 36 36 [Storable] … … 46 46 } 47 47 } 48 public T ActualValue {49 get { return GetActualValue(); }48 public new T ActualValue { 49 get { return (T)GetActualValue(); } 50 50 set { SetActualValue(value); } 51 51 } … … 80 80 return scope != null ? scope.Variables[actualName] : null; 81 81 } 82 protected virtual TGetActualValue() {82 protected override IItem GetActualValue() { 83 83 string name = TranslateName(Name, ExecutionContext); 84 84 IVariable var = LookupVariable(name); … … 95 95 return null; 96 96 } 97 protected virtual void SetActualValue(T value) { 97 protected override void SetActualValue(IItem value) { 98 T val = value as T; 99 if (val == null) 100 throw new InvalidOperationException( 101 string.Format("Type mismatch. Value is not a \"{0}\".", 102 typeof(T).GetPrettyName()) 103 ); 98 104 string name = TranslateName(Name, ExecutionContext); 99 105 IVariable var = LookupVariable(name); 100 if (var != null) var.Value = val ue;101 else ExecutionContext.Scope.Variables.Add(new Variable(name, val ue));106 if (var != null) var.Value = val; 107 else ExecutionContext.Scope.Variables.Add(new Variable(name, val)); 102 108 } 103 109 -
trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs
r2756 r2757 45 45 get { return dataType; } 46 46 } 47 public IItem ActualValue { 48 get { return GetActualValue(); } 49 set { SetActualValue(value); } 50 } 47 51 [Storable] 48 52 private ExecutionContext executionContext; 49 53 public ExecutionContext ExecutionContext { 50 54 get { return executionContext; } 51 set { executionContext = value; } 55 set { 56 if (value != executionContext) { 57 executionContext = value; 58 OnExecutionContextChanged(); 59 } 60 } 52 61 } 53 62 … … 77 86 return string.Format("{0} ({1})", Name, DataType.Name); 78 87 } 88 89 protected abstract IItem GetActualValue(); 90 protected abstract void SetActualValue(IItem value); 91 92 protected virtual void OnExecutionContextChanged() { } 79 93 } 80 94 } -
trunk/sources/HeuristicLab.Parameters/3.3/ScopeParameter.cs
r2756 r2757 35 35 [Creatable("Test")] 36 36 public class ScopeParameter : Parameter { 37 public IScopeValue {37 public new IScope ActualValue { 38 38 get { return ExecutionContext.Scope; } 39 39 } … … 52 52 return string.Format("{0} ({1})", Name, DataType.Name); 53 53 } 54 55 protected override IItem GetActualValue() { 56 return ExecutionContext.Scope; 57 } 58 protected override void SetActualValue(IItem value) { 59 throw new NotSupportedException("The actual value of a ScopeParameter cannot be set. It is always the current scope."); 60 } 54 61 } 55 62 } -
trunk/sources/HeuristicLab.Parameters/3.3/SubScopesLookupParameter.cs
r2756 r2757 32 32 /// A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope. 33 33 /// </summary> 34 [Item("SubScopesLookupParameter<T>", "A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.")]34 [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.")] 35 35 public class SubScopesLookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem { 36 36 [Storable] … … 47 47 } 48 48 49 public T[] ActualValues{50 get { return GetActualValues(); }51 set { SetActualValue s(value); }49 public new ItemArray<T> ActualValue { 50 get { return (ItemArray<T>)GetActualValue(); } 51 set { SetActualValue(value); } 52 52 } 53 53 54 54 public SubScopesLookupParameter() 55 : base("Anonymous", typeof( T)) {55 : base("Anonymous", typeof(ItemArray<T>)) { 56 56 actualName = Name; 57 57 } 58 58 public SubScopesLookupParameter(string name) 59 : base(name, typeof( T)) {59 : base(name, typeof(ItemArray<T>)) { 60 60 actualName = Name; 61 61 } 62 62 public SubScopesLookupParameter(string name, string description) 63 : base(name, description, typeof( T)) {63 : base(name, description, typeof(ItemArray<T>)) { 64 64 actualName = Name; 65 65 } … … 75 75 } 76 76 77 protected virtual T[] GetActualValues() {77 protected override IItem GetActualValue() { 78 78 string name = LookupParameter<T>.TranslateName(Name, ExecutionContext); 79 79 IScope scope = ExecutionContext.Scope; 80 T[] values = new T[scope.SubScopes.Count];80 ItemArray<T> values = new ItemArray<T>(scope.SubScopes.Count); 81 81 IVariable var; 82 82 T value; … … 97 97 return values; 98 98 } 99 protected virtual void SetActualValues(T[] values) { 99 protected override void SetActualValue(IItem value) { 100 ItemArray<T> values = value as ItemArray<T>; 101 if (values == null) 102 throw new InvalidOperationException( 103 string.Format("Type mismatch. Value is not a \"{0}\".", 104 typeof(ItemArray<T>).GetPrettyName()) 105 ); 106 100 107 string name = LookupParameter<T>.TranslateName(Name, ExecutionContext); 101 108 IScope scope = ExecutionContext.Scope; -
trunk/sources/HeuristicLab.Parameters/3.3/ValueLookupParameter.cs
r2756 r2757 32 32 /// A parameter whose value is either defined it the parameter itself or is retrieved from the scope. 33 33 /// </summary> 34 [Item("ValueLookupParameter<T>", "A parameter whose value is either defined it the parameter itself or is retrieved from thescope.")]34 [Item("ValueLookupParameter<T>", "A parameter whose value is either defined it the parameter itself or is retrieved from or written to a scope.")] 35 35 public class ValueLookupParameter<T> : Parameter, IValueLookupParameter<T> where T : class, IItem { 36 36 [Storable] … … 61 61 } 62 62 63 public T ActualValue {64 get { return GetActualValue(); }63 public new T ActualValue { 64 get { return (T)GetActualValue(); } 65 65 set { SetActualValue(value); } 66 66 } … … 137 137 return scope != null ? scope.Variables[actualName] : null; 138 138 } 139 protected virtual TGetActualValue() {139 protected override IItem GetActualValue() { 140 140 string name; 141 141 // try to get local value from context stack … … 157 157 return null; 158 158 } 159 protected virtual void SetActualValue(T value) { 159 protected override void SetActualValue(IItem value) { 160 T val = value as T; 161 if (val == null) 162 throw new InvalidOperationException( 163 string.Format("Type mismatch. Value is not a \"{0}\".", 164 typeof(T).GetPrettyName()) 165 ); 166 // try to get local value from context stack 160 167 string name; 161 // try to get local value from context stack162 168 IValueParameter<T> param = GetParameter(out name); 163 if (param != null) param.Value = val ue;169 if (param != null) param.Value = val; 164 170 else { // try to get variable from scope 165 171 IVariable var = LookupVariable(name); 166 if (var != null) var.Value = val ue;172 if (var != null) var.Value = val; 167 173 else ExecutionContext.Scope.Variables.Add(new Variable(name, value)); 168 174 } -
trunk/sources/HeuristicLab.Parameters/3.3/ValueParameter.cs
r2756 r2757 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 45 46 } 46 47 } 48 } 49 public new T ActualValue { 50 get { return Value; } 51 set { Value = value; } 47 52 } 48 53 … … 75 80 } 76 81 82 protected override IItem GetActualValue() { 83 return Value; 84 } 85 protected override void SetActualValue(IItem value) { 86 T val = value as T; 87 if (val == null) 88 throw new InvalidOperationException( 89 string.Format("Type mismatch. Value is not a \"{0}\".", 90 typeof(T).GetPrettyName()) 91 ); 92 Value = val; 93 } 94 77 95 public event EventHandler ValueChanged; 78 96 private void OnValueChanged() {
Note: See TracChangeset
for help on using the changeset viewer.