Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueLookupParameterConverter.cs @ 17394

Last change on this file since 17394 was 17394, checked in by dpiringe, 4 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.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7
8namespace HeuristicLab.JsonInterface {
9  public class ValueLookupParameterConverter : ParameterBaseConverter {
10    public override int Priority => 4;
11    public override Type ConvertableType => typeof(IValueLookupParameter);
12
13    public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
14      IValueLookupParameter param = value as IValueLookupParameter;
15     
16      item.Name = value.Name;
17      item.ActualName = param.ActualName;
18
19      object actualValue = null;
20      IEnumerable<object> actualRange = null;
21      if(param.Value != null) {
22        JsonItem tmp = root.Extract(param.Value, root);
23        tmp.Parent = item;
24        actualValue = tmp.Value;
25        actualRange = tmp.Range;
26      } else {
27        actualRange = new object[] { GetMinValue(param.DataType), GetMaxValue(param.DataType) };
28      }
29      item.Value = actualValue;
30      item.Range = actualRange;
31    }
32
33    public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {
34      IValueLookupParameter param = parameter as IValueLookupParameter;
35      param.ActualName = CastValue<string>(data.ActualName);
36      if (param.Value != null)
37        root.Inject(param.Value, data, root);
38    }
39  }
40}
Note: See TracBrowser for help on using the repository browser.