Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • deleted JsonItemArrayControl and JsonItemDefaultControl
  • redesigned architecture for JsonItem: now there are different types of JsonItem (IntJsonItem, BoolJsonItem, ...) -> for better type safety and expandability
  • fixed bug in BaseConverter for GetMinValue and GetMaxValue for IntValue, but ignored for other value types (DoubleValue, DateTimeValue, ...) because the redesign of JsonItem-Architecture can make these two methods obsolet soon
  • fixed bug in JsonItemConverter to prevent null pointer exceptions
  • refactored value and range converters -> removed complicated generic ValueTypeValueConverter and ValueRangeConverter and implemented the necessary methods directly in concrete classes (improves readability and removes the need of reflection)
  • redesigned view handling in OptimizerIntegration -> dynamically seaches for JsonItemVMBase implementations, which are connected with a view
    • this enables better scaling with more user controls
  • JsonItemVMBase implements MVVM architecture
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.AddChilds(new BoolJsonItem() {
27          Name = op.Name,
28          Value = val.Operators.ItemChecked(op),
29          Range = new bool[] { false, true }
30        });
31      }
32      return item;
33    }
34
35
36    #region Helper
37    private bool GetOperatorState(string name, IJsonItem data) {
38      foreach(var op in data.Children) {
39        if (op.Name == name && op.Value is bool) return (bool)op.Value;
40      }
41      return false;
42    }
43    #endregion
44  }
45}
Note: See TracBrowser for help on using the repository browser.