Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/MultiCheckedOperatorConverter.cs @ 17433

Last change on this file since 17433 was 17433, checked in by dpiringe, 4 years ago

#3026:

  • added property Description in IJsonItem and updated all construction calls
  • updated UnsupportedJsonItem with unsupported property Description
  • updated JsonItemBaseControl and JsonItemVMBase for new property Description
File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Common;
7using HeuristicLab.Core;
8
9namespace 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 Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
15      base.Inject(item, data, root);
16
17      dynamic val = item as dynamic;
18      foreach (var op in val.Operators)
19        val.Operators.SetItemCheckedState(op, GetOperatorState(op.Name, data));
20    }
21
22    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
23      IJsonItem item = base.Extract(value, root);
24      dynamic val = value as dynamic;
25      foreach (var op in val.Operators) {
26        item.AddChildren(new BoolJsonItem() {
27          Name = op.Name,
28          Description = op.Description,
29          Value = val.Operators.ItemChecked(op),
30          Range = new bool[] { false, true }
31        });
32      }
33      return item;
34    }
35
36
37    #region Helper
38    private bool GetOperatorState(string name, IJsonItem data) {
39      foreach(var op in data.Children) {
40        if (op.Name == name && op.Value is bool) return (bool)op.Value;
41      }
42      return false;
43    }
44    #endregion
45  }
46}
Note: See TracBrowser for help on using the repository browser.