Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Data/3.3/IntValue.cs @ 17687

Last change on this file since 17687 was 13827, checked in by jlodewyc, 9 years ago

#2582 Parameter changing busy, save file, download file and email on pass reset

File size: 3.1 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2]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;
[3306]23using System.Drawing;
[2]24using System.Text;
[3376]25using HeuristicLab.Common;
[2]26using HeuristicLab.Core;
[1853]27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[2]28
29namespace HeuristicLab.Data {
[3048]30  [Item("IntValue", "Represents an integer value.")]
[3017]31  [StorableClass]
[3054]32  public class IntValue : ValueTypeValue<int>, IComparable, IStringConvertibleValue {
[13656]33    public static new Image StaticItemImage
34    {
35      get { return new Bitmap(25, 25); }
[3306]36    }
37
[4722]38    [StorableConstructor]
39    protected IntValue(bool deserializing) : base(deserializing) { }
40    protected IntValue(IntValue original, Cloner cloner)
41      : base(original, cloner) {
42    }
[3048]43    public IntValue() : base() { }
44    public IntValue(int value) : base(value) { }
[2]45
[2663]46    public override IDeepCloneable Clone(Cloner cloner) {
[4722]47      return new IntValue(this, cloner);
[2]48    }
[2665]49
[3054]50    public virtual int CompareTo(object obj) {
[3048]51      IntValue other = obj as IntValue;
[2757]52      if (other != null)
53        return Value.CompareTo(other.Value);
54      else
55        return Value.CompareTo(obj);
56    }
[13827]57        public static IntValue Parse(string val)
58        {
59            return new IntValue(int.Parse(val));
60        }
[2757]61
[3054]62    protected virtual bool Validate(string value, out string errorMessage) {
[2694]63      int val;
64      bool valid = int.TryParse(value, out val);
65      errorMessage = string.Empty;
66      if (!valid) {
67        StringBuilder sb = new StringBuilder();
68        sb.Append("Invalid Value (Valid Value Format: \"");
69        sb.Append(FormatPatterns.GetIntFormatPattern());
70        sb.Append("\")");
71        errorMessage = sb.ToString();
72      }
73      return valid;
[2676]74    }
[3054]75    protected virtual string GetValue() {
[2665]76      return Value.ToString();
77    }
[3054]78    protected virtual bool SetValue(string value) {
[2694]79      int val;
80      if (int.TryParse(value, out val)) {
81        Value = val;
[2665]82        return true;
83      } else {
84        return false;
85      }
86    }
[3054]87
88    #region IStringConvertibleValue Members
89    bool IStringConvertibleValue.Validate(string value, out string errorMessage) {
90      return Validate(value, out errorMessage);
91    }
92    string IStringConvertibleValue.GetValue() {
93      return GetValue();
94    }
95    bool IStringConvertibleValue.SetValue(string value) {
96      return SetValue(value);
97    }
[2676]98    #endregion
[2]99  }
100}
Note: See TracBrowser for help on using the repository browser.