Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/TypeValue.cs @ 7242

Last change on this file since 7242 was 7242, checked in by ascheibe, 12 years ago

#1215 adapted to static item image change and fixed a compiler warning

File size: 2.0 KB
Line 
1using System;
2using System.Drawing;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6
7namespace HeuristicLab.Problems.MetaOptimization {
8  [Item("TypeValue", "Represents a type.")]
9  [StorableClass]
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(bool deserializing) : base(deserializing) { }
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      return value.Name;
62    }
63
64    public event EventHandler ValueChanged;
65    protected virtual void OnValueChanged() {
66      if (ValueChanged != null)
67        ValueChanged(this, EventArgs.Empty);
68      OnToStringChanged();
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.