source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeValueConverter.cs @ 17843

Last change on this file since 17843 was 17843, checked in by dpiringe, 7 weeks ago

#3026

  • removed property ConvertableType from all converters
  • removed the option to fixate or loosen the path of JsonItems (obsolete)
  • added a abstract formatter SymbolicRegressionSolutionFormatterBase as base formatter for ISymbolicRegressionSolution
  • unified the construction of exporter controls
  • code cleanup
File size: 3.3 KB
Line 
1using System;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4
5namespace HeuristicLab.JsonInterface {
6
7  public class IntValueConverter : BaseConverter {
8    public override int Priority => 1;
9
10    public override bool CanConvertType(Type t) =>
11      typeof(IntValue).IsAssignableFrom(t);
12
13    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
14      ((IntValue)item).Value = ((IntJsonItem)data).Value;
15
16    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
17      new IntJsonItem() {
18        Name = value.ItemName,
19        Description = value.ItemDescription,
20        Value = ((IntValue)value).Value,
21        Minimum = int.MinValue,
22        Maximum = int.MaxValue
23      };
24  }
25
26  public class DoubleValueConverter : BaseConverter {
27    public override int Priority => 1;
28
29    public override bool CanConvertType(Type t) =>
30      typeof(DoubleValue).IsAssignableFrom(t);
31
32    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
33      ((DoubleValue)item).Value = ((DoubleJsonItem)data).Value;
34
35    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
36      new DoubleJsonItem() {
37        Name = value.ItemName,
38        Description = value.ItemDescription,
39        Value = ((DoubleValue)value).Value,
40        Minimum = double.MinValue,
41        Maximum = double.MaxValue
42      };
43  }
44
45  public class PercentValueConverter : BaseConverter {
46    public override int Priority => 2;
47
48    public override bool CanConvertType(Type t) =>
49      typeof(PercentValue).IsAssignableFrom(t);
50
51    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
52      ((PercentValue)item).Value = ((DoubleJsonItem)data).Value;
53
54    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
55      new DoubleJsonItem() {
56        Name = value.ItemName,
57        Description = value.ItemDescription,
58        Value = ((PercentValue)value).Value,
59        Minimum = 0.0d,
60        Maximum = 1.0d
61      };
62  }
63
64  public class BoolValueConverter : BaseConverter {
65    public override int Priority => 1;
66
67    public override bool CanConvertType(Type t) =>
68      typeof(BoolValue).IsAssignableFrom(t);
69
70    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
71      ((BoolValue)item).Value = ((BoolJsonItem)data).Value;
72
73    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
74      new BoolJsonItem() {
75        Name = value.ItemName,
76        Description = value.ItemDescription,
77        Value = ((BoolValue)value).Value
78      };
79  }
80
81  public class DateTimeValueConverter : BaseConverter {
82    public override int Priority => 1;
83
84    public override bool CanConvertType(Type t) =>
85      typeof(DateTimeValue).IsAssignableFrom(t);
86
87    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
88      ((DateTimeValue)item).Value = ((DateTimeJsonItem)data).Value;
89
90    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
91      new DateTimeJsonItem() {
92        Name = value.ItemName,
93        Description = value.ItemDescription,
94        Value = ((DateTimeValue)value).Value,
95        Minimum = DateTime.MinValue,
96        Maximum = DateTime.MaxValue
97      };
98  }
99}
Note: See TracBrowser for help on using the repository browser.