Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • deleted INamedMatrixJsonItem and all corresponding classes/views, because of bad design
  • added ILookupJsonItem and IValueLookupJsonItem (incl. all corresponding implementations, VMs, Views)
  • added IResultJsonItem
  • changed type of property Control from JsonItemBaseControl to UserControl in IJsonItemVM (because the details control now builds up with linked user controls -> allows better construction of dynamic controls)
  • added all properties of INamedMatrixJsonItem in IMatrixJsonItem
  • refactored a lot of views for better usage (TableLayoutPanel is used a lot now -> for better item positioning)
  • property ActualName is now located in ILookupJsonItem instead of IJsonItem
File size: 1.6 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      param.ActualName = CastValue<string>(((IValueLookupJsonItem)data).ActualName);
16      if (param.Value != null)
17        root.Inject(param.Value, data, root);
18    }
19
20    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
21      IValueLookupParameter param = value as IValueLookupParameter;
22
23      IValueLookupJsonItem item = new ValueLookupJsonItem() {};
24
25      if (param.Value != null) {
26        IJsonItem tmp = root.Extract(param.Value, root);
27        item.Value = tmp.Value;
28        item.Range = tmp.Range;
29        item.Name = tmp.Name;
30        item.Description = tmp.Description;
31        item.AddChildren(tmp.Children);
32        item.Active = tmp.Active;
33        item.JsonItemReference = tmp;
34      } else {
35        var min = GetMinValue(param.DataType);
36        var max = GetMaxValue(param.DataType);
37        if (min != null && max != null)
38          item.Range = new object[] { min, max };
39        else
40          item.Range = null;
41      }
42      item.Name = param.Name;
43      item.Description = param.Description;
44      item.ActualName = param.ActualName;
45      return item;
46    }
47  }
48}
Note: See TracBrowser for help on using the repository browser.