Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17464 was 17433, checked in by dpiringe, 5 years ago

#3026:

  • added property Description in IJsonItem and updated all construction calls
  • updated UnsupportedJsonItem with unsupported property Description
  • updated JsonItemBaseControl and JsonItemVMBase for new property Description
File size: 1.3 KB
RevLine 
[17269]1using System;
2using System.Collections.Generic;
3using System.Linq;
[17284]4using System.Text;
[17269]5using System.Threading.Tasks;
6using HeuristicLab.Core;
7
[17284]8namespace HeuristicLab.JsonInterface {
[17281]9  public class ParameterizedItemConverter : BaseConverter {
[17394]10    public override int Priority => 2;
11    public override Type ConvertableType => typeof(IParameterizedItem);
[17269]12
[17407]13    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
[17394]14      IParameterizedItem pItem = item as IParameterizedItem;
15
[17379]16      if(data.Children != null) {
17        foreach (var sp in data.Children)
[17410]18          if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param) && param != null)
[17394]19            root.Inject(param, sp, root);
[17275]20      }
[17269]21    }
22
[17407]23    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
[17433]24      var parameterizedItem = value as IParameterizedItem;
[17407]25
[17433]26      IJsonItem item = new JsonItem() {
27        Name = value.ItemName,
28        Description = value.ItemDescription
29      };
30
[17374]31      foreach (var param in parameterizedItem.Parameters) {
[17404]32        if (!param.Hidden) {
[17406]33          IJsonItem tmp = root.Extract(param, root);
[17407]34          if (!(tmp is UnsupportedJsonItem))
[17420]35            item.AddChildren(tmp);
[17404]36        }
[17269]37      }
[17407]38
39      return item;
[17269]40    }
41  }
42}
Note: See TracBrowser for help on using the repository browser.