Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 18045 was 18045, checked in by dpiringe, 3 years ago

#3026

  • code cleanup
  • fixed a bug in ValueParameterConverter which prevented successful injection
  • changed error handling in method Main.HeadlessRun and Runner.Run
File size: 1.3 KB
Line 
1using System;
2using System.Linq;
3using HeuristicLab.Core;
4
5namespace HeuristicLab.JsonInterface {
6  public class ValueLookupParameterConverter : BaseConverter {
7    public override int Priority => 4;
8
9    public override bool CanConvertType(Type t) =>
10      t.GetInterfaces().Any(x => x == typeof(IValueLookupParameter));
11
12    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
13      IValueLookupParameter param = item as IValueLookupParameter;
14      IValueLookupJsonItem lookupItem = data as IValueLookupJsonItem;
15      param.ActualName = lookupItem.ActualName;
16      if (param.Value != null && lookupItem.ActualValue != null)
17        root.Inject(param.Value, lookupItem.ActualValue, root);
18    }
19
20    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
21      IValueLookupParameter param = value as IValueLookupParameter;
22      IValueLookupJsonItem item = new ValueLookupJsonItem();
23
24      if (param.Value != null) {
25        IJsonItem tmp = root.Extract(param.Value, root);
26        tmp.Parent = item;
27        item.ActualValue = tmp;
28      }
29      item.Name = param.Name;
30      item.Description = param.Description;
31      item.ActualName = param.ActualName;
32      return item;
33    }
34  }
35}
Note: See TracBrowser for help on using the repository browser.