Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.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.2 KB
RevLine 
[17263]1using System;
2using System.Linq;
3using HeuristicLab.Core;
4
[17284]5namespace HeuristicLab.JsonInterface {
[17407]6  public class ValueParameterConverter : BaseConverter {
[17394]7    public override int Priority => 2;
[17263]8
[17828]9    public override bool CanConvertType(Type t) =>
10      t.GetInterfaces().Any(x => x == typeof(IValueParameter));
11
[17407]12    public override void Inject(IItem value, IJsonItem data, IJsonItemConverter root) {
13      IParameter parameter = value as IParameter;
14
[18045]15      if (parameter.ActualValue == null)
16        parameter.ActualValue = Instantiate(parameter.DataType);
17      root.Inject(parameter.ActualValue, data, root);
[17342]18    }
[17263]19
[17407]20    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
21      IParameter parameter = value as IParameter;
22
[17473]23      IJsonItem item = new EmptyJsonItem() {
[17433]24        Name = parameter.Name,
25        Description = parameter.Description
[17407]26      };
27
28      if (parameter.ActualValue != null) {
29        IJsonItem tmp = root.Extract(parameter.ActualValue, root);
30        if (!(tmp is UnsupportedJsonItem)) {
[17473]31          tmp.Name = parameter.Name;
32          tmp.Description = parameter.Description;
33          item = tmp;
[17374]34        }
35      }
[17407]36      return item;
[17266]37    }
[17263]38  }
39}
Note: See TracBrowser for help on using the repository browser.