Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterizedItemConverter.cs @ 17410

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

#3026:

  • deleted JsonItemArrayControl and JsonItemDefaultControl
  • redesigned architecture for JsonItem: now there are different types of JsonItem (IntJsonItem, BoolJsonItem, ...) -> for better type safety and expandability
  • fixed bug in BaseConverter for GetMinValue and GetMaxValue for IntValue, but ignored for other value types (DoubleValue, DateTimeValue, ...) because the redesign of JsonItem-Architecture can make these two methods obsolet soon
  • fixed bug in JsonItemConverter to prevent null pointer exceptions
  • refactored value and range converters -> removed complicated generic ValueTypeValueConverter and ValueRangeConverter and implemented the necessary methods directly in concrete classes (improves readability and removes the need of reflection)
  • redesigned view handling in OptimizerIntegration -> dynamically seaches for JsonItemVMBase implementations, which are connected with a view
    • this enables better scaling with more user controls
  • JsonItemVMBase implements MVVM architecture
File size: 1.2 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 ParameterizedItemConverter : BaseConverter {
10    public override int Priority => 2;
11    public override Type ConvertableType => typeof(IParameterizedItem);
12
13    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
14      IParameterizedItem pItem = item as IParameterizedItem;
15
16      if(data.Children != null) {
17        foreach (var sp in data.Children)
18          if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param) && param != null)
19            root.Inject(param, sp, root);
20      }
21    }
22
23    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
24      IJsonItem item = new JsonItem() { Name = value.ItemName };
25
26      var parameterizedItem = value as IParameterizedItem;
27      foreach (var param in parameterizedItem.Parameters) {
28        if (!param.Hidden) {
29          IJsonItem tmp = root.Extract(param, root);
30          if (!(tmp is UnsupportedJsonItem))
31            item.AddChilds(tmp);
32        }
33      }
34
35      return item;
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.