Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs @ 17834

Last change on this file since 17834 was 17828, checked in by dpiringe, 3 years ago

#3026

  • removed the option to set the value for JsonItems via exporter
    • reworked some base controls
    • added new controls for JsonItem specific properties (e.g. ArrayResizable)
    • deleted a lot of obsolet controls
  • removed the Enable checkbox in the detail view of JsonItems
  • exporter now clones the IOptimizer object
  • added a check + message for unsupported exports
  • list of JsonItems now includes unsupported JsonItems (disabled and marked with 'unsupported')
  • refactored the converter type check
    • now every converter has to specify its supported type(s)
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 ValueParameterConverter : BaseConverter {
10    public override int Priority => 2;
11    public override Type ConvertableType => typeof(IValueParameter);
12
13    public override bool CanConvertType(Type t) =>
14      t.GetInterfaces().Any(x => x == typeof(IValueParameter));
15
16    public override void Inject(IItem value, IJsonItem data, IJsonItemConverter root) {
17      IParameter parameter = value as IParameter;
18
19      if (parameter.ActualValue == null)
20        parameter.ActualValue = Instantiate(parameter.DataType);
21
22      if(parameter.ActualValue != null) {
23          if (data.Children == null || data.Children.Count() == 0)
24            root.Inject(parameter.ActualValue, data, root);
25          else
26            root.Inject(parameter.ActualValue, data, root);
27         
28      }
29    }
30
31    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
32      IParameter parameter = value as IParameter;
33
34      IJsonItem item = new EmptyJsonItem() {
35        Name = parameter.Name,
36        Description = parameter.Description
37      };
38
39      if (parameter.ActualValue != null) {
40        IJsonItem tmp = root.Extract(parameter.ActualValue, root);
41        if (!(tmp is UnsupportedJsonItem)) {
42          tmp.Name = parameter.Name;
43          tmp.Description = parameter.Description;
44          item = tmp;
45        }
46      }
47      return item;
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.