Last change
on this file since 17406 was
17406,
checked in by dpiringe, 4 years ago
|
#3026
- added interfaces IJsonItem and IJsonItemValidator
- replaced every reference JsonItem with IJsonItem
|
File size:
1.4 KB
|
Line | |
---|
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 : ParameterBaseConverter {
|
---|
10 | public override int Priority => 4;
|
---|
11 | public override Type ConvertableType => typeof(IValueLookupParameter);
|
---|
12 |
|
---|
13 | public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) {
|
---|
14 | IValueLookupParameter param = value as IValueLookupParameter;
|
---|
15 |
|
---|
16 | item.Name = value.Name;
|
---|
17 | item.ActualName = param.ActualName;
|
---|
18 |
|
---|
19 | object actualValue = null;
|
---|
20 | IEnumerable<object> actualRange = null;
|
---|
21 | if(param.Value != null) {
|
---|
22 | IJsonItem tmp = root.Extract(param.Value, root);
|
---|
23 | tmp.Parent = item;
|
---|
24 | actualValue = tmp.Value;
|
---|
25 | actualRange = tmp.Range;
|
---|
26 | } else {
|
---|
27 | actualRange = new object[] { GetMinValue(param.DataType), GetMaxValue(param.DataType) };
|
---|
28 | }
|
---|
29 | item.Value = actualValue;
|
---|
30 | item.Range = actualRange;
|
---|
31 | }
|
---|
32 |
|
---|
33 | public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) {
|
---|
34 | IValueLookupParameter param = parameter as IValueLookupParameter;
|
---|
35 | param.ActualName = CastValue<string>(data.ActualName);
|
---|
36 | if (param.Value != null)
|
---|
37 | root.Inject(param.Value, data, root);
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.