using System; using System.Drawing; using HeuristicLab.Common; using HeuristicLab.Core; using HEAL.Attic; namespace HeuristicLab.Problems.MetaOptimization { [Item("TypeValue", "Represents a type.")] [StorableType("156764EA-AA45-45DE-81CC-E5FC8A54DE87")] public class TypeValue : Item { public static new Image StaticItemImage { get { return HeuristicLab.Common.Resources.VSImageLibrary.Field; } } [Storable] protected Type value; public virtual Type Value { get { return value; } set { if (ReadOnly) throw new NotSupportedException("Value cannot be set. TypeValue is read-only."); if (!value.Equals(this.value)) { this.value = value; OnValueChanged(); } } } [Storable] protected bool readOnly; public virtual bool ReadOnly { get { return readOnly; } } public TypeValue() : base() { this.readOnly = false; } public TypeValue(Type value) : base() { this.Value = value; this.readOnly = false; } [StorableConstructor] protected TypeValue(StorableConstructorFlag _) : base(_) { } protected TypeValue(TypeValue original, Cloner cloner) : base(original, cloner) { this.value = original.value; this.readOnly = original.readOnly; } public override IDeepCloneable Clone(Cloner cloner) { return new TypeValue(this, cloner); } public virtual TypeValue AsReadOnly() { TypeValue readOnlyValueTypeValue = (TypeValue)this.Clone(); readOnlyValueTypeValue.readOnly = true; return readOnlyValueTypeValue; } public override string ToString() { if (value == null) return "No Type information"; return value.Name; } public event EventHandler ValueChanged; protected virtual void OnValueChanged() { if (ValueChanged != null) ValueChanged(this, EventArgs.Empty); OnToStringChanged(); } } }