Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • refactored JsonTemplateInstantiator -> now returns a InstantiatorResult which contains the optimizer and an IEnumerable of IResultJsonItem
  • code cleanup in JCGenerator
  • relocated the serialization of json items into IJsonItem with method GenerateJObject (virtual base implementation in JsonItem)
    • this allows custom serialization for json items (example: ValueLookupJsonItem)
    • items of interface IIntervalRestrictedJsonItem have a custom implementation of GenerateJObject -> hides Minimum and Maximum if the values are the physically min/max of their type
  • code cleanup in BaseConverter
File size: 1.3 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 : BaseConverter {
10    public override int Priority => 4;
11    public override Type ConvertableType => typeof(IValueLookupParameter);
12
13    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
14      IValueLookupParameter param = item as IValueLookupParameter;
15      IValueLookupJsonItem lookupItem = data as IValueLookupJsonItem;
16      param.ActualName = lookupItem.ActualName;
17      if (param.Value != null && lookupItem.ActualValue != null)
18        root.Inject(param.Value, lookupItem.ActualValue, root);
19    }
20
21    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
22      IValueLookupParameter param = value as IValueLookupParameter;
23
24      IValueLookupJsonItem item = new ValueLookupJsonItem() {};
25
26      if (param.Value != null) {
27        IJsonItem tmp = root.Extract(param.Value, root);
28        tmp.Parent = item;
29        //item.AddChildren(tmp.Children);
30        item.ActualValue = tmp;
31      }
32      item.Name = param.Name;
33      item.Description = param.Description;
34      item.ActualName = param.ActualName;
35      return item;
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.