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 |
|
---|
8 | namespace HeuristicLab.JsonInterface {
|
---|
9 | public class ValueLookupParameterConverter : BaseConverter {
|
---|
10 | public override int Priority => 4;
|
---|
11 | public override Type ConvertableType => typeof(IValueLookupParameter);
|
---|
12 |
|
---|
13 | public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
|
---|
14 | IValueLookupParameter param = item as IValueLookupParameter;
|
---|
15 | param.ActualName = CastValue<string>(((IValueLookupJsonItem)data).ActualName);
|
---|
16 | if (param.Value != null)
|
---|
17 | root.Inject(param.Value, data, root);
|
---|
18 | }
|
---|
19 |
|
---|
20 | public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
|
---|
21 | IValueLookupParameter param = value as IValueLookupParameter;
|
---|
22 |
|
---|
23 | IValueLookupJsonItem item = new ValueLookupJsonItem() {};
|
---|
24 |
|
---|
25 | if (param.Value != null) {
|
---|
26 | IJsonItem tmp = root.Extract(param.Value, root);
|
---|
27 | item.Value = tmp.Value;
|
---|
28 | item.Range = tmp.Range;
|
---|
29 | item.Name = tmp.Name;
|
---|
30 | item.Description = tmp.Description;
|
---|
31 | item.AddChildren(tmp.Children);
|
---|
32 | item.Active = tmp.Active;
|
---|
33 | item.JsonItemReference = tmp;
|
---|
34 | } else {
|
---|
35 | var min = GetMinValue(param.DataType);
|
---|
36 | var max = GetMaxValue(param.DataType);
|
---|
37 | if (min != null && max != null)
|
---|
38 | item.Range = new object[] { min, max };
|
---|
39 | else
|
---|
40 | item.Range = null;
|
---|
41 | }
|
---|
42 | item.Name = param.Name;
|
---|
43 | item.Description = param.Description;
|
---|
44 | item.ActualName = param.ActualName;
|
---|
45 | return item;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|