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

Last change on this file since 17843 was 17843, checked in by dpiringe, 2 months ago

#3026

  • removed property ConvertableType from all converters
  • removed the option to fixate or loosen the path of JsonItems (obsolete)
  • added a abstract formatter SymbolicRegressionSolutionFormatterBase as base formatter for ISymbolicRegressionSolution
  • unified the construction of exporter controls
  • code cleanup
File size: 1.8 KB
RevLine 
[17353]1using System;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4
5namespace HeuristicLab.JsonInterface {
6
[17410]7  public class IntRangeConverter : BaseConverter {
[17394]8    public override int Priority => 1;
[17410]9
[17828]10    public override bool CanConvertType(Type t) =>
[17843]11      typeof(IntRange).IsAssignableFrom(t);
[17828]12
[17410]13    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
14      IntRange range = item as IntRange;
[17451]15      IntRangeJsonItem cdata = data as IntRangeJsonItem;
[17473]16      range.Start = cdata.MinValue;
17      range.End = cdata.MaxValue;
[17410]18    }
19
20    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
21      IntRange range = value as IntRange;
[17420]22      return new IntRangeJsonItem() {
[17473]23        Name = value.ItemName,
[17433]24        Description = value.ItemDescription,
[17473]25        MinValue = range.Start,
26        MaxValue = range.End,
27        Minimum = int.MinValue,
28        Maximum = int.MaxValue
[17410]29      };
30    }
[17394]31  }
[17410]32
33  public class DoubleRangeConverter : BaseConverter {
[17394]34    public override int Priority => 1;
[17353]35
[17828]36    public override bool CanConvertType(Type t) =>
[17843]37      typeof(DoubleRange).IsAssignableFrom(t);
[17828]38
[17407]39    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
[17410]40      DoubleRange range = item as DoubleRange;
[17451]41      DoubleRangeJsonItem cdata = data as DoubleRangeJsonItem;
[17473]42      range.Start = cdata.MinValue;
43      range.End = cdata.MaxValue;
[17353]44    }
[17407]45
46    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
[17410]47      DoubleRange range = value as DoubleRange;
[17420]48      return new DoubleRangeJsonItem() {
[17473]49        Name = value.ItemName,
[17433]50        Description = value.ItemDescription,
[17473]51        MinValue = range.Start,
52        MaxValue = range.End,
53        Minimum = double.MinValue,
54        Maximum = double.MaxValue
[17407]55      };
56    }
[17353]57  }
58}
Note: See TracBrowser for help on using the repository browser.