Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs @ 18043

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

#3026

  • code cleanup
File size: 1.3 KB
Line 
1using System;
2using System.Linq;
3using HeuristicLab.Core;
4
5namespace HeuristicLab.JsonInterface {
6  public class ValueParameterConverter : BaseConverter {
7    public override int Priority => 2;
8
9    public override bool CanConvertType(Type t) =>
10      t.GetInterfaces().Any(x => x == typeof(IValueParameter));
11
12    public override void Inject(IItem value, IJsonItem data, IJsonItemConverter root) {
13      IParameter parameter = value as IParameter;
14
15      if (!(data is EmptyJsonItem)) {
16        if (parameter.ActualValue == null)
17          parameter.ActualValue = Instantiate(parameter.DataType);
18        root.Inject(parameter.ActualValue, data, root);
19      }
20    }
21
22    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
23      IParameter parameter = value as IParameter;
24
25      IJsonItem item = new EmptyJsonItem() {
26        Name = parameter.Name,
27        Description = parameter.Description
28      };
29
30      if (parameter.ActualValue != null) {
31        IJsonItem tmp = root.Extract(parameter.ActualValue, root);
32        if (!(tmp is UnsupportedJsonItem)) {
33          tmp.Name = parameter.Name;
34          tmp.Description = parameter.Description;
35          item = tmp;
36        }
37      }
38      return item;
39    }
40  }
41}
Note: See TracBrowser for help on using the repository browser.