Line | |
---|
1 | using System;
|
---|
2 | using HEAL.Attic;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 |
|
---|
6 | namespace HeuristicLab.Parameters {
|
---|
7 | [Item("ContextLookupParameter", "A parameter that looks up contexts by type.")]
|
---|
8 | [StorableType("4ac189c8-6cf3-48fd-bf79-392d35a872db")]
|
---|
9 | public abstract class ContextLookupParameter<T> : ContextParameter, IContextLookupParameter<T>
|
---|
10 | where T : class, IParameterizedItem {
|
---|
11 |
|
---|
12 | public new T ActualValue {
|
---|
13 | get { return (T)base.ActualValue; }
|
---|
14 | }
|
---|
15 |
|
---|
16 | [StorableConstructor]
|
---|
17 | protected ContextLookupParameter(StorableConstructorFlag _) : base(_) { }
|
---|
18 | protected ContextLookupParameter(ContextLookupParameter<T> original, Cloner cloner) : base(original, cloner) { }
|
---|
19 | protected ContextLookupParameter() : this("ContextLookup." + typeof(T).Name) { }
|
---|
20 | protected ContextLookupParameter(string name) : this(name, string.Empty) { }
|
---|
21 | protected ContextLookupParameter(string name, string description) : base(name, description, typeof(T)) {
|
---|
22 | Hidden = true;
|
---|
23 | }
|
---|
24 |
|
---|
25 | protected override IItem GetActualValueFromContext() {
|
---|
26 | IItem item = null;
|
---|
27 | var context = ExecutionContext;
|
---|
28 | while (context != null) {
|
---|
29 | if (context.Item != null && typeof(T).IsAssignableFrom(context.Item.GetType())) {
|
---|
30 | item = context.Item;
|
---|
31 | break;
|
---|
32 | }
|
---|
33 | context = context.Parent;
|
---|
34 | }
|
---|
35 | return item;
|
---|
36 | }
|
---|
37 |
|
---|
38 | protected override void SetActualValue(IItem value) {
|
---|
39 | throw new NotSupportedException("The context lookup parameter may not be used to set an item.");
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.