Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueLookupParameterConverter.cs @ 17407

Last change on this file since 17407 was 17407, checked in by dpiringe, 4 years ago

#3026:

  • simplified converter inheritance:
    • BaseConverter now only has Inject and Extract from IJsonItemConverter as abstract methods
    • removed ParameterBaseConverter
    • concrete converters have to initialize their JsonItem now -> enables better handling with different types of JsonItem
File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7
8namespace 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>(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      IJsonItem item = new JsonItem() {
24        Name = param.Name,
25        ActualName = param.ActualName
26      };
27
28      object actualValue = null;
29      IEnumerable<object> actualRange = null;
30      if (param.Value != null) {
31        IJsonItem tmp = root.Extract(param.Value, root);
32        tmp.Parent = item;
33        actualValue = tmp.Value;
34        actualRange = tmp.Range;
35      } else {
36        actualRange = new object[] { GetMinValue(param.DataType), GetMaxValue(param.DataType) };
37      }
38      item.Value = actualValue;
39      item.Range = actualRange;
40      return item;
41    }
42  }
43}
Note: See TracBrowser for help on using the repository browser.