Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17712 was 17473, checked in by dpiringe, 5 years ago

#3026:

  • refactored inheritance structure of json items, now the default JsonItem is an abstract class without properties Value and Range -> splitted up into new interfaces
  • updated view models for new json item structure
  • updated SingleLineArrayJsonWriter
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    public override Type ConvertableType => typeof(IParameterizedItem);
12
13    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
14      IParameterizedItem pItem = item as IParameterizedItem;
15
16      if(data.Children != null) {
17        foreach (var sp in data.Children)
18          if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param) && param != null)
19            root.Inject(param, sp, root);
20      }
21    }
22
23    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
24      var parameterizedItem = value as IParameterizedItem;
25
26      IJsonItem item = new EmptyJsonItem() {
27        Name = value.ItemName,
28        Description = value.ItemDescription
29      };
30
31      foreach (var param in parameterizedItem.Parameters) {
32        if (!param.Hidden) {
33          IJsonItem tmp = root.Extract(param, root);
34          if (!(tmp is UnsupportedJsonItem))
35            item.AddChildren(tmp);
36        }
37      }
38
39      return item;
40    }
41  }
42}
Note: See TracBrowser for help on using the repository browser.