Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • added error output for failed runner initialization
  • reorganised some final view models
  • TargetedJsonItemType (in JsonItemVMBase) now automatically returns the type of the defined JsonItem
  • code cleanup
  • refactored RegressionProblemDataConverter
  • added lots of comments
  • added new view for StringArrayJsonItem
  • added new UI component for concrete restricted items and used it in JsonItemConcreteItemArrayControl and JsonItemValidValuesControl
File size: 1.5 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 void Inject(IItem value, IJsonItem data, IJsonItemConverter root) {
14      IParameter parameter = value as IParameter;
15
16      if (parameter.ActualValue == null)
17        parameter.ActualValue = Instantiate(parameter.DataType);
18
19      if(parameter.ActualValue != null) {
20          if (data.Children == null || data.Children.Count() == 0)
21            root.Inject(parameter.ActualValue, data, root);
22          else
23            root.Inject(parameter.ActualValue, data, root);
24         
25      }
26    }
27
28    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
29      IParameter parameter = value as IParameter;
30
31      IJsonItem item = new EmptyJsonItem() {
32        Name = parameter.Name,
33        Description = parameter.Description
34      };
35
36      if (parameter.ActualValue != null) {
37        IJsonItem tmp = root.Extract(parameter.ActualValue, root);
38        if (!(tmp is UnsupportedJsonItem)) {
39          tmp.Name = parameter.Name;
40          tmp.Description = parameter.Description;
41          item = tmp;
42        }
43      }
44      return item;
45    }
46  }
47}
Note: See TracBrowser for help on using the repository browser.