Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026

  • added some test cases for JsonInterface
  • deleted the HeuristicLab namespace part in a lot of test classes (this caused a lot of compile errors)
  • enhanced the OS path logic for absolute and relative path in JsonTemplateGenerator and JsonTemplateInstantiator
  • fixed a bug in ValueParameterConverter -> the injection logic was not working correctly
  • changed the folder determination in Main.cs for the HeadlessRun method
  • added a new abstract type of JsonItem IntervalRestrictedJsonItem for JsonItems with a need of Minimum and Maximum bounds but without a specific value
    • changed in RangedJsonItem the base class from IntervalRestrictedValueJsonItem to IntervalRestrictedJsonItem
File size: 1.3 KB
RevLine 
[17263]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7
[17284]8namespace HeuristicLab.JsonInterface {
[17407]9  public class ValueParameterConverter : BaseConverter {
[17394]10    public override int Priority => 2;
[17263]11
[17828]12    public override bool CanConvertType(Type t) =>
13      t.GetInterfaces().Any(x => x == typeof(IValueParameter));
14
[17407]15    public override void Inject(IItem value, IJsonItem data, IJsonItemConverter root) {
16      IParameter parameter = value as IParameter;
17
[18040]18      if (!(data is EmptyJsonItem)) {
19        if (parameter.ActualValue == null)
20          parameter.ActualValue = Instantiate(parameter.DataType);
21        root.Inject(parameter.ActualValue, data, root);
[17439]22      }
[17342]23    }
[17263]24
[17407]25    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
26      IParameter parameter = value as IParameter;
27
[17473]28      IJsonItem item = new EmptyJsonItem() {
[17433]29        Name = parameter.Name,
30        Description = parameter.Description
[17407]31      };
32
33      if (parameter.ActualValue != null) {
34        IJsonItem tmp = root.Extract(parameter.ActualValue, root);
35        if (!(tmp is UnsupportedJsonItem)) {
[17473]36          tmp.Name = parameter.Name;
37          tmp.Description = parameter.Description;
38          item = tmp;
[17374]39        }
40      }
[17407]41      return item;
[17266]42    }
[17263]43  }
44}
Note: See TracBrowser for help on using the repository browser.