Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file was 18077, checked in by dpiringe, 2 years ago

#3026

  • added the dockerhub readme file
  • fixed a bug which caused changed values (changed by events) to be overwritten with wrong values
File size: 1.2 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 (parameter.ActualValue == null && data.Active)
16        parameter.ActualValue = Instantiate(parameter.DataType);
17      root.Inject(parameter.ActualValue, data, root);
18    }
19
20    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
21      IParameter parameter = value as IParameter;
22
23      IJsonItem item = new EmptyJsonItem() {
24        Name = parameter.Name,
25        Description = parameter.Description
26      };
27
28      if (parameter.ActualValue != null) {
29        IJsonItem tmp = root.Extract(parameter.ActualValue, root);
30        if (!(tmp is UnsupportedJsonItem)) {
31          tmp.Name = parameter.Name;
32          tmp.Description = parameter.Description;
33          item = tmp;
34        }
35      }
36      return item;
37    }
38  }
39}
Note: See TracBrowser for help on using the repository browser.