[5313] | 1 | using System;
|
---|
[7242] | 2 | using System.Drawing;
|
---|
| 3 | using HeuristicLab.Common;
|
---|
[5313] | 4 | using HeuristicLab.Core;
|
---|
[16574] | 5 | using HEAL.Attic;
|
---|
[5313] | 6 |
|
---|
| 7 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
| 8 | [Item("TypeValue", "Represents a type.")]
|
---|
[16574] | 9 | [StorableType("156764EA-AA45-45DE-81CC-E5FC8A54DE87")]
|
---|
[5313] | 10 | public class TypeValue : Item {
|
---|
[7242] | 11 | public static new Image StaticItemImage {
|
---|
[5313] | 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 |
|
---|
[7242] | 34 | public TypeValue()
|
---|
| 35 | : base() {
|
---|
[5313] | 36 | this.readOnly = false;
|
---|
| 37 | }
|
---|
[7242] | 38 | public TypeValue(Type value)
|
---|
| 39 | : base() {
|
---|
[5313] | 40 | this.Value = value;
|
---|
| 41 | this.readOnly = false;
|
---|
| 42 | }
|
---|
| 43 | [StorableConstructor]
|
---|
[16574] | 44 | protected TypeValue(StorableConstructorFlag _) : base(_) { }
|
---|
[5313] | 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() {
|
---|
[8087] | 61 | if (value == null) return "No Type information";
|
---|
[5313] | 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 | }
|
---|