Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17712 was 17483, checked in by dpiringe, 5 years ago

#3026:

  • added readme JsonInterfaceReadMe.txt
  • removed dead code
  • fixed a bug in JsonItemConverter -> now the type comparison should work as intended
File size: 1.9 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
17    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
18      IntRange range = item as IntRange;
[17451]19      IntRangeJsonItem cdata = data as IntRangeJsonItem;
[17473]20      range.Start = cdata.MinValue;
21      range.End = cdata.MaxValue;
[17410]22    }
23
24    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
25      IntRange range = value as IntRange;
[17420]26      return new IntRangeJsonItem() {
[17473]27        Name = value.ItemName,
[17433]28        Description = value.ItemDescription,
[17473]29        MinValue = range.Start,
30        MaxValue = range.End,
31        Minimum = int.MinValue,
32        Maximum = int.MaxValue
[17410]33      };
34    }
[17394]35  }
[17410]36
37  public class DoubleRangeConverter : BaseConverter {
[17394]38    public override int Priority => 1;
39    public override Type ConvertableType => typeof(DoubleRange);
[17353]40
[17407]41    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
[17410]42      DoubleRange range = item as DoubleRange;
[17451]43      DoubleRangeJsonItem cdata = data as DoubleRangeJsonItem;
[17473]44      range.Start = cdata.MinValue;
45      range.End = cdata.MaxValue;
[17353]46    }
[17407]47
48    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
[17410]49      DoubleRange range = value as DoubleRange;
[17420]50      return new DoubleRangeJsonItem() {
[17473]51        Name = value.ItemName,
[17433]52        Description = value.ItemDescription,
[17473]53        MinValue = range.Start,
54        MaxValue = range.End,
55        Minimum = double.MinValue,
56        Maximum = double.MaxValue
[17407]57      };
58    }
[17353]59  }
60}
Note: See TracBrowser for help on using the repository browser.