Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17828 was 17828, checked in by dpiringe, 3 years 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
RevLine 
[17353]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
[17410]13  public class IntRangeConverter : BaseConverter {
[17394]14    public override int Priority => 1;
15    public override Type ConvertableType => typeof(IntRange);
[17410]16
[17828]17    public override bool CanConvertType(Type t) =>
18      ConvertableType.IsAssignableFrom(t);
19
[17410]20    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
21      IntRange range = item as IntRange;
[17451]22      IntRangeJsonItem cdata = data as IntRangeJsonItem;
[17473]23      range.Start = cdata.MinValue;
24      range.End = cdata.MaxValue;
[17410]25    }
26
27    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
28      IntRange range = value as IntRange;
[17420]29      return new IntRangeJsonItem() {
[17473]30        Name = value.ItemName,
[17433]31        Description = value.ItemDescription,
[17473]32        MinValue = range.Start,
33        MaxValue = range.End,
34        Minimum = int.MinValue,
35        Maximum = int.MaxValue
[17410]36      };
37    }
[17394]38  }
[17410]39
40  public class DoubleRangeConverter : BaseConverter {
[17394]41    public override int Priority => 1;
42    public override Type ConvertableType => typeof(DoubleRange);
[17353]43
[17828]44    public override bool CanConvertType(Type t) =>
45      ConvertableType.IsAssignableFrom(t);
46
[17407]47    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
[17410]48      DoubleRange range = item as DoubleRange;
[17451]49      DoubleRangeJsonItem cdata = data as DoubleRangeJsonItem;
[17473]50      range.Start = cdata.MinValue;
51      range.End = cdata.MaxValue;
[17353]52    }
[17407]53
54    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
[17410]55      DoubleRange range = value as DoubleRange;
[17420]56      return new DoubleRangeJsonItem() {
[17473]57        Name = value.ItemName,
[17433]58        Description = value.ItemDescription,
[17473]59        MinValue = range.Start,
60        MaxValue = range.End,
61        Minimum = double.MinValue,
62        Maximum = double.MaxValue
[17407]63      };
64    }
[17353]65  }
66}
Note: See TracBrowser for help on using the repository browser.