Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17712 was 17483, checked in by dpiringe, 5 years ago

#3026:

  • added readme JsonInterfaceReadMe.txt
  • removed dead code
  • fixed a bug in JsonItemConverter -> now the type comparison should work as intended
File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Text;
6using System.Threading.Tasks;
7using HeuristicLab.Common;
8using HeuristicLab.Core;
9using HeuristicLab.Data;
10
11namespace HeuristicLab.JsonInterface {
12
13  public class IntRangeConverter : BaseConverter {
14    public override int Priority => 1;
15    public override Type ConvertableType => typeof(IntRange);
16
17    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
18      IntRange range = item as IntRange;
19      IntRangeJsonItem cdata = data as IntRangeJsonItem;
20      range.Start = cdata.MinValue;
21      range.End = cdata.MaxValue;
22    }
23
24    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
25      IntRange range = value as IntRange;
26      return new IntRangeJsonItem() {
27        Name = value.ItemName,
28        Description = value.ItemDescription,
29        MinValue = range.Start,
30        MaxValue = range.End,
31        Minimum = int.MinValue,
32        Maximum = int.MaxValue
33      };
34    }
35  }
36
37  public class DoubleRangeConverter : BaseConverter {
38    public override int Priority => 1;
39    public override Type ConvertableType => typeof(DoubleRange);
40
41    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
42      DoubleRange range = item as DoubleRange;
43      DoubleRangeJsonItem cdata = data as DoubleRangeJsonItem;
44      range.Start = cdata.MinValue;
45      range.End = cdata.MaxValue;
46    }
47
48    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
49      DoubleRange range = value as DoubleRange;
50      return new DoubleRangeJsonItem() {
51        Name = value.ItemName,
52        Description = value.ItemDescription,
53        MinValue = range.Start,
54        MaxValue = range.End,
55        Minimum = double.MinValue,
56        Maximum = double.MaxValue
57      };
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.