Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/Value.cs @ 17800

Last change on this file since 17800 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 2.6 KB
RevLine 
[13534]1#region License Information
2/* HeuristicLab
[17181]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[13534]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 {
[15081]28    public virtual string GetValue() {
29      return string.Empty;
30    }
31
[13534]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)
[15081]37        };
[13534]38        case "IntValue": return new IntValue() {
39          Name = name,
40          Value = int.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
[15081]41        };
[13534]42        case "LongValue": return new LongValue() {
43          Name = name,
44          Value = long.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
[15081]45        };
[13534]46        case "FloatValue": return new FloatValue() {
47          Name = name,
48          Value = float.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
[15081]49        };
[13534]50        case "DoubleValue": return new DoubleValue() {
51          Name = name,
52          Value = double.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
[15081]53        };
[13534]54        case "PercentValue": return new PercentValue() {
55          Name = name,
56          Value = double.Parse(Regex.Match(strValue, "[0-9.,]+").Value, CultureInfo.CurrentCulture.NumberFormat) / 100.0
[15081]57        };
[13534]58        case "StringValue": return new StringValue() {
59          Name = name,
60          Value = strValue
[15081]61        };
[13534]62        case "TimeSpanValue": return new TimeSpanValue() {
63          Name = name,
64          Value = long.Parse(strValue, CultureInfo.CurrentCulture.NumberFormat)
[15081]65        };
[13534]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.