1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using System.Drawing;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 | using HeuristicLab.Common;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
12 | [Item("TypeValue", "Represents a type.")]
|
---|
13 | [StorableClass]
|
---|
14 | public class TypeValue : Item {
|
---|
15 | public override Image ItemImage {
|
---|
16 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Field; }
|
---|
17 | }
|
---|
18 |
|
---|
19 | [Storable]
|
---|
20 | protected Type value;
|
---|
21 | public virtual Type Value {
|
---|
22 | get { return value; }
|
---|
23 | set {
|
---|
24 | if (ReadOnly) throw new NotSupportedException("Value cannot be set. TypeValue is read-only.");
|
---|
25 | if (!value.Equals(this.value)) {
|
---|
26 | this.value = value;
|
---|
27 | OnValueChanged();
|
---|
28 | }
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | [Storable]
|
---|
33 | protected bool readOnly;
|
---|
34 | public virtual bool ReadOnly {
|
---|
35 | get { return readOnly; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public TypeValue() : base() {
|
---|
39 | this.readOnly = false;
|
---|
40 | }
|
---|
41 | public TypeValue(Type value) : base() {
|
---|
42 | this.Value = value;
|
---|
43 | this.readOnly = false;
|
---|
44 | }
|
---|
45 | [StorableConstructor]
|
---|
46 | protected TypeValue(bool deserializing) : base(deserializing) { }
|
---|
47 | protected TypeValue(TypeValue original, Cloner cloner)
|
---|
48 | : base(original, cloner) {
|
---|
49 | this.value = original.value;
|
---|
50 | this.readOnly = original.readOnly;
|
---|
51 | }
|
---|
52 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
53 | return new TypeValue(this, cloner);
|
---|
54 | }
|
---|
55 |
|
---|
56 | public virtual TypeValue AsReadOnly() {
|
---|
57 | TypeValue readOnlyValueTypeValue = (TypeValue)this.Clone();
|
---|
58 | readOnlyValueTypeValue.readOnly = true;
|
---|
59 | return readOnlyValueTypeValue;
|
---|
60 | }
|
---|
61 |
|
---|
62 | public override string ToString() {
|
---|
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 | }
|
---|