source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/MultiCheckedOperatorTransformer.cs @ 17280

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

#3026

  • renamed CustomWriter to CustomJsonWriter and extracted it into a separate file
  • removed property ParameterizedItems from Component
  • added helper methods for path generation in Component
  • reverted the single parameter array idea back to the FreeParameters and StaticParameters idea
  • now there hidden parameters are also handled
File size: 1.5 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
13      data.Default = value.GetType().Name;
14      data.Operators = new List<Component>();
15      /*
16      if (data.ParameterizedItems == null)
17        data.ParameterizedItems = new List<Component>();
18      data.ParameterizedItems.Add(data);
19      */
20      dynamic val = value.Cast<dynamic>();
21      foreach (var op in val.Operators) {
22        data.Operators.Add(new Component() {
23          Name = op.Name,
24          Default = val.Operators.ItemChecked(op),
25          Range = new object[] { false, true },
26          Path = data.Path + "." + op.Name
27        });
28      }
29      return data;
30    }
31
32    public override void InjectData(IItem item, Component data) {
33      base.InjectData(item, data);
34
35      dynamic val = item.Cast<dynamic>();
36      foreach (var op in val.Operators) {
37        val.Operators.SetItemCheckedState(op, GetOperatorState(op.Name, data));
38      }
39    }
40
41    private bool GetOperatorState(string name, Component data) {
42      foreach(var op in data.Operators) {
43        if (op.Name == name) return op.Default.Cast<bool>();
44      }
45      return false;
46    }
47  }
48}
Note: See TracBrowser for help on using the repository browser.