1 | using System;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Data;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.JsonInterface {
|
---|
6 |
|
---|
7 | public class IntRangeConverter : BaseConverter {
|
---|
8 | public override int Priority => 1;
|
---|
9 |
|
---|
10 | public override bool CanConvertType(Type t) =>
|
---|
11 | typeof(IntRange).IsAssignableFrom(t);
|
---|
12 |
|
---|
13 | public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
|
---|
14 | IntRange range = item as IntRange;
|
---|
15 | IntRangeJsonItem cdata = data as IntRangeJsonItem;
|
---|
16 | range.Start = cdata.MinValue;
|
---|
17 | range.End = cdata.MaxValue;
|
---|
18 | }
|
---|
19 |
|
---|
20 | public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
|
---|
21 | IntRange range = value as IntRange;
|
---|
22 | return new IntRangeJsonItem() {
|
---|
23 | Name = value.ItemName,
|
---|
24 | Description = value.ItemDescription,
|
---|
25 | MinValue = range.Start,
|
---|
26 | MaxValue = range.End,
|
---|
27 | Minimum = int.MinValue,
|
---|
28 | Maximum = int.MaxValue
|
---|
29 | };
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | public class DoubleRangeConverter : BaseConverter {
|
---|
34 | public override int Priority => 1;
|
---|
35 |
|
---|
36 | public override bool CanConvertType(Type t) =>
|
---|
37 | typeof(DoubleRange).IsAssignableFrom(t);
|
---|
38 |
|
---|
39 | public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
|
---|
40 | DoubleRange range = item as DoubleRange;
|
---|
41 | DoubleRangeJsonItem cdata = data as DoubleRangeJsonItem;
|
---|
42 | range.Start = cdata.MinValue;
|
---|
43 | range.End = cdata.MaxValue;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
|
---|
47 | DoubleRange range = value as DoubleRange;
|
---|
48 | return new DoubleRangeJsonItem() {
|
---|
49 | Name = value.ItemName,
|
---|
50 | Description = value.ItemDescription,
|
---|
51 | MinValue = range.Start,
|
---|
52 | MaxValue = range.End,
|
---|
53 | Minimum = double.MinValue,
|
---|
54 | Maximum = double.MaxValue
|
---|
55 | };
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|