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
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7
8namespace HeuristicLab.JsonInterface {
9  public class ValueParameterConverter : BaseConverter {
10    public override int Priority => 2;
11
12    public override bool CanConvertType(Type t) =>
13      t.GetInterfaces().Any(x => x == typeof(IValueParameter));
14
15    public override void Inject(IItem value, IJsonItem data, IJsonItemConverter root) {
16      IParameter parameter = value as IParameter;
17
18      if (parameter.ActualValue == null)
19        parameter.ActualValue = Instantiate(parameter.DataType);
20
21      if(parameter.ActualValue != null) {
22          if (data.Children == null || data.Children.Count() == 0)
23            root.Inject(parameter.ActualValue, data, root);
24          else
25            root.Inject(parameter.ActualValue, data, root);
26         
27      }
28    }
29
30    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
31      IParameter parameter = value as IParameter;
32
33      IJsonItem item = new EmptyJsonItem() {
34        Name = parameter.Name,
35        Description = parameter.Description
36      };
37
38      if (parameter.ActualValue != null) {
39        IJsonItem tmp = root.Extract(parameter.ActualValue, root);
40        if (!(tmp is UnsupportedJsonItem)) {
41          tmp.Name = parameter.Name;
42          tmp.Description = parameter.Description;
43          item = tmp;
44        }
45      }
46      return item;
47    }
48  }
49}
Note: See TracBrowser for help on using the repository browser.