Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2915-AbsoluteSymbol/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/Value.cs @ 16154

Last change on this file since 16154 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.Globalization;
24using System.Text.RegularExpressions;
25
26namespace HeuristicLab.Clients.OKB.RunCreation {
27  public partial class Value {
28    public virtual string GetValue() {
29      return string.Empty;
30    }
31
32    public static Value Create(string name, string strValue, string type) {
33      switch (type) {
34        case "BoolValue": return new BoolValue() {
35          Name = name,
36          Value = bool.Parse(strValue)
37        };
38        case "IntValue": return new IntValue() {
39          Name = name,
40          Value = int.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
41        };
42        case "LongValue": return new LongValue() {
43          Name = name,
44          Value = long.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
45        };
46        case "FloatValue": return new FloatValue() {
47          Name = name,
48          Value = float.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
49        };
50        case "DoubleValue": return new DoubleValue() {
51          Name = name,
52          Value = double.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
53        };
54        case "PercentValue": return new PercentValue() {
55          Name = name,
56          Value = double.Parse(Regex.Match(strValue, "[0-9.,]+").Value, CultureInfo.CurrentCulture.NumberFormat) / 100.0
57        };
58        case "StringValue": return new StringValue() {
59          Name = name,
60          Value = strValue
61        };
62        case "TimeSpanValue": return new TimeSpanValue() {
63          Name = name,
64          Value = long.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
65        };
66        default: throw new ArgumentException(string.Format("type {0} is unknown", type), "type");
67      }
68    }
69  }
70}
Note: See TracBrowser for help on using the repository browser.