Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17473 was 17473, checked in by dpiringe, 4 years ago

#3026:

  • refactored inheritance structure of json items, now the default JsonItem is an abstract class without properties Value and Range -> splitted up into new interfaces
  • updated view models for new json item structure
  • updated SingleLineArrayJsonWriter
File size: 2.0 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 = "[OverridableParamName]",
28        Name = value.ItemName,
29        Description = value.ItemDescription,
30        MinValue = range.Start,
31        MaxValue = range.End,
32        Minimum = int.MinValue,
33        Maximum = int.MaxValue
34      };
35    }
36  }
37
38  public class DoubleRangeConverter : BaseConverter {
39    public override int Priority => 1;
40    public override Type ConvertableType => typeof(DoubleRange);
41
42    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
43      DoubleRange range = item as DoubleRange;
44      DoubleRangeJsonItem cdata = data as DoubleRangeJsonItem;
45      range.Start = cdata.MinValue;
46      range.End = cdata.MaxValue;
47    }
48
49    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
50      DoubleRange range = value as DoubleRange;
51      return new DoubleRangeJsonItem() {
52        //Name = "[OverridableParamName]",
53        Name = value.ItemName,
54        Description = value.ItemDescription,
55        MinValue = range.Start,
56        MaxValue = range.End,
57        Minimum = double.MinValue,
58        Maximum = double.MaxValue
59      };
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.