Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/TypeValue.cs @ 16574

Last change on this file since 16574 was 16574, checked in by gkronber, 5 years ago

#2520: changed HeuristicLab.MetaOptimization addon to compile with new HL.Persistence

File size: 2.1 KB
Line 
1using System;
2using System.Drawing;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6using HEAL.Attic;
7
8namespace HeuristicLab.Problems.MetaOptimization {
9  [Item("TypeValue", "Represents a type.")]
10  [StorableType("156764EA-AA45-45DE-81CC-E5FC8A54DE87")]
11  public class TypeValue : Item {
12    public static new Image StaticItemImage {
13      get { return HeuristicLab.Common.Resources.VSImageLibrary.Field; }
14    }
15
16    [Storable]
17    protected Type value;
18    public virtual Type Value {
19      get { return value; }
20      set {
21        if (ReadOnly) throw new NotSupportedException("Value cannot be set. TypeValue is read-only.");
22        if (!value.Equals(this.value)) {
23          this.value = value;
24          OnValueChanged();
25        }
26      }
27    }
28
29    [Storable]
30    protected bool readOnly;
31    public virtual bool ReadOnly {
32      get { return readOnly; }
33    }
34
35    public TypeValue()
36      : base() {
37      this.readOnly = false;
38    }
39    public TypeValue(Type value)
40      : base() {
41      this.Value = value;
42      this.readOnly = false;
43    }
44    [StorableConstructor]
45    protected TypeValue(StorableConstructorFlag _) : base(_) { }
46    protected TypeValue(TypeValue original, Cloner cloner)
47      : base(original, cloner) {
48      this.value = original.value;
49      this.readOnly = original.readOnly;
50    }
51    public override IDeepCloneable Clone(Cloner cloner) {
52      return new TypeValue(this, cloner);
53    }
54
55    public virtual TypeValue AsReadOnly() {
56      TypeValue readOnlyValueTypeValue = (TypeValue)this.Clone();
57      readOnlyValueTypeValue.readOnly = true;
58      return readOnlyValueTypeValue;
59    }
60
61    public override string ToString() {
62      if (value == null) return "No Type information";
63      return value.Name;
64    }
65
66    public event EventHandler ValueChanged;
67    protected virtual void OnValueChanged() {
68      if (ValueChanged != null)
69        ValueChanged(this, EventArgs.Empty);
70      OnToStringChanged();
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.