Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/MultiCheckedOperatorTransformer.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  public class MultiCheckedOperatorTransformer : ParameterizedItemTransformer {
10    public override Component ExtractData(IItem value) {
11      Component data = base.ExtractData(value);
12      data.Default = value.GetType().Name;
13
14      data.Operators = new List<Component>();
15      dynamic val = value.Cast<dynamic>();
16      foreach (var op in val.Operators) {
17        data.Operators.Add(new Component() {
18          Name = op.Name,
19          Default = val.Operators.ItemChecked(op),
20          Range = new object[] { false, true }
21        });
22      }
23      return data;
24    }
25
26    public override void InjectData(IItem item, Component data) {
27      base.InjectData(item, data);
28
29      dynamic val = item.Cast<dynamic>();
30      foreach (var op in val.Operators) {
31        val.Operators.SetItemCheckedState(op, GetOperatorState(op.Name, data));
32      }
33    }
34
35    private bool GetOperatorState(string name, Component data) {
36      foreach(var op in data.Operators) {
37        if (op.Name == name) return op.Default.Cast<bool>();
38      }
39      return false;
40    }
41  }
42}
Note: See TracBrowser for help on using the repository browser.