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

Last change on this file since 17828 was 17828, checked in by dpiringe, 2 months ago

#3026

  • removed the option to set the value for JsonItems via exporter
    • reworked some base controls
    • added new controls for JsonItem specific properties (e.g. ArrayResizable)
    • deleted a lot of obsolet controls
  • removed the Enable checkbox in the detail view of JsonItems
  • exporter now clones the IOptimizer object
  • added a check + message for unsupported exports
  • list of JsonItems now includes unsupported JsonItems (disabled and marked with 'unsupported')
  • refactored the converter type check
    • now every converter has to specify its supported type(s)
File size: 1.4 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    public override Type ConvertableType => typeof(IParameterizedItem);
12
13    public override bool CanConvertType(Type t) =>
14      t.GetInterfaces().Any(x => x == typeof(IParameterizedItem));
15
16    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
17      IParameterizedItem pItem = item as IParameterizedItem;
18
19      if(data.Children != null) {
20        foreach (var sp in data.Children)
21          if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param) && param != null)
22            root.Inject(param, sp, root);
23      }
24    }
25
26    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
27      var parameterizedItem = value as IParameterizedItem;
28
29      IJsonItem item = new EmptyJsonItem() {
30        Name = value.ItemName,
31        Description = value.ItemDescription
32      };
33
34      foreach (var param in parameterizedItem.Parameters) {
35        if (!param.Hidden) {
36          IJsonItem tmp = root.Extract(param, root);
37          if (!(tmp is UnsupportedJsonItem))
38            item.AddChildren(tmp);
39        }
40      }
41
42      return item;
43    }
44
45  }
46}
Note: See TracBrowser for help on using the repository browser.