source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ParameterizedItemConverter.cs @ 17281

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

#3026: renamed Transformers -> ...Transformer to ...Converter, ITypeTransformer to IJsonItemConverter, Transformer to JsonItemConverter

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