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

Last change on this file since 17843 was 17843, checked in by dpiringe, 7 weeks 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.3 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 ParameterizedItemConverter : BaseConverter {
10    public override int Priority => 2;
11
12    public override bool CanConvertType(Type t) =>
13      t.GetInterfaces().Any(x => x == typeof(IParameterizedItem));
14
15    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
16      IParameterizedItem pItem = item as IParameterizedItem;
17
18      if(data.Children != null) {
19        foreach (var sp in data.Children)
20          if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param) && param != null)
21            root.Inject(param, sp, root);
22      }
23    }
24
25    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
26      var parameterizedItem = value as IParameterizedItem;
27
28      IJsonItem item = new EmptyJsonItem() {
29        Name = value.ItemName,
30        Description = value.ItemDescription
31      };
32
33      foreach (var param in parameterizedItem.Parameters) {
34        if (!param.Hidden) {
35          IJsonItem tmp = root.Extract(param, root);
36          if (!(tmp is UnsupportedJsonItem))
37            item.AddChildren(tmp);
38        }
39      }
40
41      return item;
42    }
43
44  }
45}
Note: See TracBrowser for help on using the repository browser.