Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • added property Description in IJsonItem and updated all construction calls
  • updated UnsupportedJsonItem with unsupported property Description
  • updated JsonItemBaseControl and JsonItemVMBase for new property Description
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      IntArrayJsonItem cdata = data as IntArrayJsonItem;
20      range.Start = cdata.Value[0];
21      range.End = cdata.Value[1];
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        Description = value.ItemDescription,
29        Value = new int[] { range.Start, range.End },
30        Range = new int[] { int.MinValue, int.MaxValue }
31      };
32    }
33  }
34
35  public class DoubleRangeConverter : BaseConverter {
36    public override int Priority => 1;
37    public override Type ConvertableType => typeof(DoubleRange);
38
39    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
40      DoubleRange range = item as DoubleRange;
41      DoubleArrayJsonItem cdata = data as DoubleArrayJsonItem;
42      range.Start = cdata.Value[0];
43      range.End = cdata.Value[1];
44    }
45
46    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
47      DoubleRange range = value as DoubleRange;
48      return new DoubleRangeJsonItem() {
49        Name = "[OverridableParamName]",
50        Description = value.ItemDescription,
51        Value = new double[] { range.Start, range.End },
52        Range = new double[] { double.MinValue, double.MaxValue }
53      };
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.