#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 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.Parameters {
///
/// A base class for parameters.
///
[Item("Parameter", "A base class for parameters.")]
[StorableClass("743FB88F-6E73-4252-9474-AE62E4139027")]
public abstract class Parameter : NamedItem, IParameter {
public override Image ItemImage {
get {
if ((dataType != null) && (typeof(IOperator).IsAssignableFrom(dataType)))
return HeuristicLab.Common.Resources.VSImageLibrary.Method;
else
return base.ItemImage;
}
}
public override bool CanChangeName {
get { return false; }
}
public override bool CanChangeDescription {
get { return false; }
}
[Storable]
private Type dataType;
public Type DataType {
get { return dataType; }
}
[Storable(DefaultValue = false)]
private bool hidden;
public bool Hidden {
get { return hidden; }
set {
if (value != hidden) {
hidden = value;
OnHiddenChanged();
}
}
}
public IItem ActualValue {
get { return GetActualValue(); }
set { SetActualValue(value); }
}
[StorableConstructor]
protected Parameter(bool deserializing)
: base(deserializing) {
}
protected Parameter(Parameter original, Cloner cloner)
: base(original, cloner) {
dataType = original.dataType;
hidden = original.hidden;
}
protected Parameter()
: base("Anonymous") {
dataType = typeof(IItem);
hidden = false;
}
protected Parameter(string name, Type dataType)
: base(name) {
if (dataType == null) throw new ArgumentNullException();
this.dataType = dataType;
hidden = false;
}
protected Parameter(string name, string description, Type dataType)
: base(name, description) {
if (dataType == null) throw new ArgumentNullException();
this.dataType = dataType;
hidden = false;
}
public override string ToString() {
return Name;
}
protected abstract IItem GetActualValue();
protected abstract void SetActualValue(IItem value);
public event EventHandler HiddenChanged;
protected virtual void OnHiddenChanged() {
EventHandler handler = HiddenChanged;
if (handler != null) handler(this, EventArgs.Empty);
}
}
}