Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/TypeValue.cs @ 8665

Last change on this file since 8665 was 8535, checked in by jkarder, 12 years ago

#1853:

  • enhanced combinations count calculation
  • restructured code
  • minor code improvements
  • added license information
File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Drawing;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Encodings.ParameterConfigurationEncoding {
29  [Item("TypeValue", "Represents a type.")]
30  [StorableClass]
31  public class TypeValue : Item {
32    public static new Image StaticItemImage {
33      get { return HeuristicLab.Common.Resources.VSImageLibrary.Field; }
34    }
35
36    [Storable]
37    protected Type value;
38    public virtual Type Value {
39      get { return value; }
40      set {
41        if (ReadOnly) throw new NotSupportedException("Value cannot be set. TypeValue is read-only.");
42        if (!value.Equals(this.value)) {
43          this.value = value;
44          OnValueChanged();
45        }
46      }
47    }
48
49    [Storable]
50    protected bool readOnly;
51    public virtual bool ReadOnly {
52      get { return readOnly; }
53    }
54
55    #region Constructors and Cloning
56    [StorableConstructor]
57    protected TypeValue(bool deserializing) : base(deserializing) { }
58    protected TypeValue(TypeValue original, Cloner cloner)
59      : base(original, cloner) {
60      this.value = original.value;
61      this.readOnly = original.readOnly;
62    }
63    public TypeValue()
64      : base() {
65      this.readOnly = false;
66    }
67    public TypeValue(Type value)
68      : base() {
69      this.Value = value;
70      this.readOnly = false;
71    }
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new TypeValue(this, cloner);
74    }
75    #endregion
76
77    public virtual TypeValue AsReadOnly() {
78      TypeValue readOnlyValueTypeValue = (TypeValue)this.Clone();
79      readOnlyValueTypeValue.readOnly = true;
80      return readOnlyValueTypeValue;
81    }
82
83    public override string ToString() {
84      if (value == null) return "No Type information";
85      return value.Name;
86    }
87
88    public event EventHandler ValueChanged;
89    protected virtual void OnValueChanged() {
90      if (ValueChanged != null)
91        ValueChanged(this, EventArgs.Empty);
92      OnToStringChanged();
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.