1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Common;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.JsonInterface {
|
---|
10 | public class MultiCheckedOperatorConverter : ParameterizedItemConverter {
|
---|
11 | public override int Priority => 3;
|
---|
12 | public override Type ConvertableType => typeof(ICheckedMultiOperator<>);
|
---|
13 |
|
---|
14 | public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
|
---|
15 | base.Populate(value, item, root);
|
---|
16 |
|
---|
17 | dynamic val = value as dynamic;
|
---|
18 | foreach (var op in val.Operators) {
|
---|
19 | item.AddChilds(new JsonItem() {
|
---|
20 | Name = op.Name,
|
---|
21 | Value = val.Operators.ItemChecked(op),
|
---|
22 | Range = new object[] { false, true }
|
---|
23 | });
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
|
---|
28 | base.InjectData(item, data, root);
|
---|
29 |
|
---|
30 | dynamic val = item as dynamic;
|
---|
31 | foreach (var op in val.Operators)
|
---|
32 | val.Operators.SetItemCheckedState(op, GetOperatorState(op.Name, data));
|
---|
33 | }
|
---|
34 |
|
---|
35 | private bool GetOperatorState(string name, JsonItem data) {
|
---|
36 | foreach(var op in data.Children) {
|
---|
37 | if (op.Name == name && op.Value is bool) return (bool)op.Value;
|
---|
38 | }
|
---|
39 | return false;
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|