Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026

  • removed property ConvertableType from all converters
  • removed the option to fixate or loosen the path of JsonItems (obsolete)
  • added a abstract formatter SymbolicRegressionSolutionFormatterBase as base formatter for ISymbolicRegressionSolution
  • unified the construction of exporter controls
  • code cleanup
File size: 1.5 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
[17473]18      if (parameter.ActualValue == null)
[17342]19        parameter.ActualValue = Instantiate(parameter.DataType);
[17439]20
21      if(parameter.ActualValue != null) {
[17519]22          if (data.Children == null || data.Children.Count() == 0)
[17439]23            root.Inject(parameter.ActualValue, data, root);
24          else
[17483]25            root.Inject(parameter.ActualValue, data, root);
[17439]26         
27      }
[17342]28    }
[17263]29
[17407]30    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
31      IParameter parameter = value as IParameter;
32
[17473]33      IJsonItem item = new EmptyJsonItem() {
[17433]34        Name = parameter.Name,
35        Description = parameter.Description
[17407]36      };
37
38      if (parameter.ActualValue != null) {
39        IJsonItem tmp = root.Extract(parameter.ActualValue, root);
40        if (!(tmp is UnsupportedJsonItem)) {
[17473]41          tmp.Name = parameter.Name;
42          tmp.Description = parameter.Description;
43          item = tmp;
[17374]44        }
45      }
[17407]46      return item;
[17266]47    }
[17263]48  }
49}
Note: See TracBrowser for help on using the repository browser.