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

Last change on this file since 17828 was 17828, checked in by dpiringe, 3 months ago

#3026

  • removed the option to set the value for JsonItems via exporter
    • reworked some base controls
    • added new controls for JsonItem specific properties (e.g. ArrayResizable)
    • deleted a lot of obsolet controls
  • removed the Enable checkbox in the detail view of JsonItems
  • exporter now clones the IOptimizer object
  • added a check + message for unsupported exports
  • list of JsonItems now includes unsupported JsonItems (disabled and marked with 'unsupported')
  • refactored the converter type check
    • now every converter has to specify its supported type(s)
File size: 2.1 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 bool CanConvertType(Type t) =>
18      ConvertableType.IsAssignableFrom(t);
19
20    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
21      IntRange range = item as IntRange;
22      IntRangeJsonItem cdata = data as IntRangeJsonItem;
23      range.Start = cdata.MinValue;
24      range.End = cdata.MaxValue;
25    }
26
27    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
28      IntRange range = value as IntRange;
29      return new IntRangeJsonItem() {
30        Name = value.ItemName,
31        Description = value.ItemDescription,
32        MinValue = range.Start,
33        MaxValue = range.End,
34        Minimum = int.MinValue,
35        Maximum = int.MaxValue
36      };
37    }
38  }
39
40  public class DoubleRangeConverter : BaseConverter {
41    public override int Priority => 1;
42    public override Type ConvertableType => typeof(DoubleRange);
43
44    public override bool CanConvertType(Type t) =>
45      ConvertableType.IsAssignableFrom(t);
46
47    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
48      DoubleRange range = item as DoubleRange;
49      DoubleRangeJsonItem cdata = data as DoubleRangeJsonItem;
50      range.Start = cdata.MinValue;
51      range.End = cdata.MaxValue;
52    }
53
54    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
55      DoubleRange range = value as DoubleRange;
56      return new DoubleRangeJsonItem() {
57        Name = value.ItemName,
58        Description = value.ItemDescription,
59        MinValue = range.Start,
60        MaxValue = range.End,
61        Minimum = double.MinValue,
62        Maximum = double.MaxValue
63      };
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.