Changeset 9195 for trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs
- Timestamp:
- 01/29/13 14:39:02 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs
r7259 r9195 22 22 using System; 23 23 using System.Drawing; 24 using System.Threading;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 33 32 [Item("Parameter", "A base class for parameters.")] 34 33 [StorableClass] 35 public abstract class Parameter : NamedItem, IParameter , IStatefulItem{34 public abstract class Parameter : NamedItem, IParameter { 36 35 public override Image ItemImage { 37 36 get { … … 67 66 } 68 67 69 private Lazy<ThreadLocal<IItem>> cachedActualValues;70 68 public IItem ActualValue { 71 get { 72 if (cachedActualValues.Value.Value == null) cachedActualValues.Value.Value = GetActualValue(); 73 return cachedActualValues.Value.Value; 74 } 75 set { 76 cachedActualValues.Value.Value = value; 77 SetActualValue(value); 78 } 79 } 80 private Lazy<ThreadLocal<IExecutionContext>> executionContexts; 81 public IExecutionContext ExecutionContext { 82 get { return executionContexts.Value.Value; } 83 set { 84 if (value != executionContexts.Value.Value) { 85 executionContexts.Value.Value = value; 86 cachedActualValues.Value.Value = null; 87 } 88 } 69 get { return GetActualValue(); } 70 set { SetActualValue(value); } 89 71 } 90 72 … … 92 74 protected Parameter(bool deserializing) 93 75 : base(deserializing) { 94 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);95 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);96 76 } 97 77 protected Parameter(Parameter original, Cloner cloner) … … 99 79 dataType = original.dataType; 100 80 hidden = original.hidden; 101 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);102 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);103 81 } 104 82 protected Parameter() … … 106 84 dataType = typeof(IItem); 107 85 hidden = false; 108 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);109 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);110 86 } 111 87 protected Parameter(string name, Type dataType) … … 114 90 this.dataType = dataType; 115 91 hidden = false; 116 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);117 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);118 92 } 119 93 protected Parameter(string name, string description, Type dataType) … … 122 96 this.dataType = dataType; 123 97 hidden = false; 124 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);125 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);126 }127 128 public virtual void InitializeState() { }129 public virtual void ClearState() {130 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);131 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);132 98 } 133 99
Note: See TracChangeset
for help on using the changeset viewer.