Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/ParameterTransformer/ParameterizedItemTransformer.cs @ 17275

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

#3026

  • deleted Util.cs
  • BaseTransformer merges now the component with its reference (if a reference exists) -> easier handling for transformers with parameterizedItems
  • MultiCheckedOperatorTransformer now sets the type name as default value
  • added a type list at the end of the template file -> is needed to instantiate objects
  • changed JCGenerator and JCInstantiator to test a format where FreeParameters and StaticParameters are saved as single Parameter array
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 ParameterizedItemTransformer : BaseTransformer {
11   
12    public override void InjectData(IItem item, Component data) {
13      IParameterizedItem pItem = item.Cast<IParameterizedItem>();
14
15      if(data.Parameters != null) {
16        foreach (var sp in data.Parameters)
17          if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param))
18            Transformer.Inject(param, sp);
19      }
20    }
21
22    public override Component ExtractData(IItem value) {
23      List<Component> list = new List<Component>();
24
25      Component obj = new Component();
26      obj.Name = value.ItemName;
27      obj.Type = value.GetType().AssemblyQualifiedName;
28      obj.ParameterizedItems = list;
29      obj.Parameters = new List<Component>();
30      list.Add(obj);
31
32      foreach (var param in value.Cast<IParameterizedItem>().Parameters) {
33        if (!param.Hidden) {
34          Component data = Transformer.Extract(param);
35          obj.Parameters.Add(data);
36          if(data.ParameterizedItems != null)
37            list.AddRange(data.ParameterizedItems);
38        }
39      }
40      return obj;
41    }
42  }
43}
Note: See TracBrowser for help on using the repository browser.