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

Last change on this file since 17284 was 17284, checked in by dpiringe, 3 years ago

#3026: renamed namespace and project from HeuristicLab.Manufacture to HeuristicLab.JsonInterface

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 void InjectData(IItem item, JsonItem data) {
11      IParameterizedItem pItem = item.Cast<IParameterizedItem>();
12
13      if(data.Parameters != null) {
14        foreach (var sp in data.Parameters)
15          if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param))
16            JsonItemConverter.Inject(param, sp);
17      }
18    }
19
20    public override JsonItem ExtractData(IItem value) {
21      JsonItem item = new JsonItem();
22      item.Name = value.ItemName;
23      item.Type = value.GetType().AssemblyQualifiedName;
24      item.Path = value.ItemName;
25
26      foreach (var param in value.Cast<IParameterizedItem>().Parameters) {
27        JsonItem data = JsonItemConverter.Extract(param);
28        data.Name = param.Name;
29        data.Path = param.Name;
30        data.PrependPath(item.Path);
31        data.UpdatePaths();
32       
33        if (item.Parameters == null)
34          item.Parameters = new List<JsonItem>();
35        item.Parameters.Add(data);
36      }
37      return item;
38    }
39  }
40}
Note: See TracBrowser for help on using the repository browser.