Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17399 was 17394, checked in by dpiringe, 5 years ago

#3026:

  • deleted: ConvertableAttribute, DummyConverter, ObjectExtensions
  • renamed: CustomJsonWriter -> SingleLineArrayJsonWriter, JCInstantiator -> JsonTemplateInstantiator
  • added: JsonItemConverterFactory, UnsupportedJsonItem
  • IJsonItemConverter:
    • added two new properties: Priority and ConvertableType -> because converters are automatically collected by plugin infrastructure now
    • Extract, Inject references a root converter now -> typically an instance of JsonItemConverter -> to prevent cycles
  • JsonItemConverter:
    • now implements the interface IJsonItemConverter
    • is now a dynamic class
    • is only instantiable with an factory (JsonItemConverterFactory)
    • still has the old (but now public) static methods Extract and Inject (without ref param IJsonItemConverter root) -> creates instance with factory and calls methods of instance
    • removed register and unregister methods, because the factory collects all converters automatically now (on first call of Create)
    • has cycle detection for Extract and Inject
    • renamed method Get to GetConverter
File size: 1.3 KB
RevLine 
[17269]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
[17353]6using HeuristicLab.Common;
[17269]7using HeuristicLab.Core;
8
[17284]9namespace HeuristicLab.JsonInterface {
[17281]10  public class MultiCheckedOperatorConverter : ParameterizedItemConverter {
[17394]11    public override int Priority => 3;
12    public override Type ConvertableType => typeof(ICheckedMultiOperator<>);
[17280]13
[17394]14    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
15      base.Populate(value, item, root);
16
17      dynamic val = value as dynamic;
[17269]18      foreach (var op in val.Operators) {
[17394]19        item.AddChilds(new JsonItem() {
[17269]20          Name = op.Name,
[17342]21          Value = val.Operators.ItemChecked(op),
[17379]22          Range = new object[] { false, true }
[17269]23        });
24      }
25    }
26
[17394]27    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
28      base.InjectData(item, data, root);
[17269]29
[17394]30      dynamic val = item as dynamic;
[17322]31      foreach (var op in val.Operators)
[17269]32        val.Operators.SetItemCheckedState(op, GetOperatorState(op.Name, data));
33    }
34
[17283]35    private bool GetOperatorState(string name, JsonItem data) {
[17379]36      foreach(var op in data.Children) {
[17394]37        if (op.Name == name && op.Value is bool) return (bool)op.Value;
[17269]38      }
39      return false;
40    }
41  }
42}
Note: See TracBrowser for help on using the repository browser.