#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Drawing; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Encodings.ParameterConfigurationEncoding { [Item("TypeValue", "Represents a type.")] [StorableClass] 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; } } #region Constructors and Cloning [StorableConstructor] protected TypeValue(bool deserializing) : base(deserializing) { } protected TypeValue(TypeValue original, Cloner cloner) : base(original, cloner) { this.value = original.value; this.readOnly = original.readOnly; } public TypeValue() : base() { this.readOnly = false; } public TypeValue(Type value) : base() { this.Value = value; this.readOnly = false; } public override IDeepCloneable Clone(Cloner cloner) { return new TypeValue(this, cloner); } #endregion 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(); } } }