Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2520 Update plugin dependencies and references for HL.MetaOptimization for new persistence

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