Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17843 was 17843, checked in by dpiringe, 3 years 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: 1.8 KB
Line 
1using System;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4
5namespace HeuristicLab.JsonInterface {
6
7  public class IntRangeConverter : BaseConverter {
8    public override int Priority => 1;
9
10    public override bool CanConvertType(Type t) =>
11      typeof(IntRange).IsAssignableFrom(t);
12
13    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
14      IntRange range = item as IntRange;
15      IntRangeJsonItem cdata = data as IntRangeJsonItem;
16      range.Start = cdata.MinValue;
17      range.End = cdata.MaxValue;
18    }
19
20    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
21      IntRange range = value as IntRange;
22      return new IntRangeJsonItem() {
23        Name = value.ItemName,
24        Description = value.ItemDescription,
25        MinValue = range.Start,
26        MaxValue = range.End,
27        Minimum = int.MinValue,
28        Maximum = int.MaxValue
29      };
30    }
31  }
32
33  public class DoubleRangeConverter : BaseConverter {
34    public override int Priority => 1;
35
36    public override bool CanConvertType(Type t) =>
37      typeof(DoubleRange).IsAssignableFrom(t);
38
39    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
40      DoubleRange range = item as DoubleRange;
41      DoubleRangeJsonItem cdata = data as DoubleRangeJsonItem;
42      range.Start = cdata.MinValue;
43      range.End = cdata.MaxValue;
44    }
45
46    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
47      DoubleRange range = value as DoubleRange;
48      return new DoubleRangeJsonItem() {
49        Name = value.ItemName,
50        Description = value.ItemDescription,
51        MinValue = range.Start,
52        MaxValue = range.End,
53        Minimum = double.MinValue,
54        Maximum = double.MaxValue
55      };
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.