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

Last change on this file since 17828 was 17828, checked in by dpiringe, 2 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: 3.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7using HeuristicLab.Data;
8
9namespace HeuristicLab.JsonInterface {
10
11  public class IntValueConverter : BaseConverter {
12    public override int Priority => 1;
13    public override Type ConvertableType => typeof(IntValue);
14
15    public override bool CanConvertType(Type t) =>
16      ConvertableType.IsAssignableFrom(t);
17
18    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
19      ((IntValue)item).Value = ((IntJsonItem)data).Value;
20
21    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
22      new IntJsonItem() {
23        Name = value.ItemName,
24        Description = value.ItemDescription,
25        Value = ((IntValue)value).Value,
26        Minimum = int.MinValue,
27        Maximum = int.MaxValue
28      };
29  }
30
31  public class DoubleValueConverter : BaseConverter {
32    public override int Priority => 1;
33    public override Type ConvertableType => typeof(DoubleValue);
34
35    public override bool CanConvertType(Type t) =>
36      ConvertableType.IsAssignableFrom(t);
37
38    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
39      ((DoubleValue)item).Value = ((DoubleJsonItem)data).Value;
40
41    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
42      new DoubleJsonItem() {
43        Name = value.ItemName,
44        Description = value.ItemDescription,
45        Value = ((DoubleValue)value).Value,
46        Minimum = double.MinValue,
47        Maximum = double.MaxValue
48      };
49  }
50
51  public class PercentValueConverter : BaseConverter {
52    public override int Priority => 2;
53    public override Type ConvertableType => typeof(PercentValue);
54
55    public override bool CanConvertType(Type t) =>
56      ConvertableType.IsAssignableFrom(t);
57
58    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
59      ((PercentValue)item).Value = ((DoubleJsonItem)data).Value;
60
61    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
62      new DoubleJsonItem() {
63        Name = value.ItemName,
64        Description = value.ItemDescription,
65        Value = ((PercentValue)value).Value,
66        Minimum = 0.0d,
67        Maximum = 1.0d
68      };
69  }
70
71  public class BoolValueConverter : BaseConverter {
72    public override int Priority => 1;
73    public override Type ConvertableType => typeof(BoolValue);
74
75    public override bool CanConvertType(Type t) =>
76      ConvertableType.IsAssignableFrom(t);
77
78    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
79      ((BoolValue)item).Value = ((BoolJsonItem)data).Value;
80
81    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
82      new BoolJsonItem() {
83        Name = value.ItemName,
84        Description = value.ItemDescription,
85        Value = ((BoolValue)value).Value
86      };
87  }
88
89  public class DateTimeValueConverter : BaseConverter {
90    public override int Priority => 1;
91    public override Type ConvertableType => typeof(DateTimeValue);
92
93    public override bool CanConvertType(Type t) =>
94      ConvertableType.IsAssignableFrom(t);
95
96    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
97      ((DateTimeValue)item).Value = ((DateTimeJsonItem)data).Value;
98
99    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
100      new DateTimeJsonItem() {
101        Name = value.ItemName,
102        Description = value.ItemDescription,
103        Value = ((DateTimeValue)value).Value,
104        Minimum = DateTime.MinValue,
105        Maximum = DateTime.MaxValue
106      };
107  }
108}
Note: See TracBrowser for help on using the repository browser.