1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Data;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.JsonInterface {
|
---|
10 |
|
---|
11 | public class IntValueConverter : ValueTypeValueConverter<IntValue, int> {
|
---|
12 | public override int Priority => 1;
|
---|
13 | public override Type ConvertableType => typeof(IntValue);
|
---|
14 | }
|
---|
15 |
|
---|
16 | public class DoubleValueConverter : ValueTypeValueConverter<DoubleValue, double> {
|
---|
17 | public override int Priority => 1;
|
---|
18 | public override Type ConvertableType => typeof(DoubleValue);
|
---|
19 | }
|
---|
20 |
|
---|
21 | public class PercentValueConverter : ValueTypeValueConverter<PercentValue, double> {
|
---|
22 | public override int Priority => 2;
|
---|
23 | public override Type ConvertableType => typeof(PercentValue);
|
---|
24 | }
|
---|
25 |
|
---|
26 | public class BoolValueConverter : ValueTypeValueConverter<BoolValue, bool> {
|
---|
27 | public override int Priority => 1;
|
---|
28 | public override Type ConvertableType => typeof(BoolValue);
|
---|
29 | }
|
---|
30 |
|
---|
31 | public class DateTimeValueConverter : ValueTypeValueConverter<DateTimeValue, DateTime> {
|
---|
32 | public override int Priority => 1;
|
---|
33 | public override Type ConvertableType => typeof(DateTimeValue);
|
---|
34 | }
|
---|
35 |
|
---|
36 | public abstract class ValueTypeValueConverter<ValueType, T> : BaseConverter
|
---|
37 | where ValueType : ValueTypeValue<T>
|
---|
38 | where T : struct {
|
---|
39 |
|
---|
40 | public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
|
---|
41 | ((ValueType)item).Value = CastValue<T>(data.Value);
|
---|
42 |
|
---|
43 | public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
|
---|
44 | item.Name = "[OverridableParamName]";
|
---|
45 | item.Value = ((ValueType)value).Value;
|
---|
46 | item.Range = new object[] { GetMinValue(typeof(T)), GetMaxValue(typeof(T)) };
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|