Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueRangeConverter.cs @ 17417

Last change on this file since 17417 was 17410, checked in by dpiringe, 5 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.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Text;
6using System.Threading.Tasks;
7using HeuristicLab.Common;
8using HeuristicLab.Core;
9using HeuristicLab.Data;
10
11namespace HeuristicLab.JsonInterface {
12
13  public class IntRangeConverter : BaseConverter {
14    public override int Priority => 1;
15    public override Type ConvertableType => typeof(IntRange);
16
17    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
18      IntRange range = item as IntRange;
19      IntArrayJsonItem cdata = data as IntArrayJsonItem;
20      range.Start = cdata.Value[0];
21      range.End = cdata.Value[1];
22    }
23
24    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
25      IntRange range = value as IntRange;
26      return new IntArrayJsonItem() {
27        Name = "[OverridableParamName]",
28        Value = new int[] { range.Start, range.End },
29        Range = new int[] { int.MinValue, int.MaxValue }
30      };
31    }
32  }
33
34  public class DoubleRangeConverter : BaseConverter {
35    public override int Priority => 1;
36    public override Type ConvertableType => typeof(DoubleRange);
37
38    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
39      DoubleRange range = item as DoubleRange;
40      DoubleArrayJsonItem cdata = data as DoubleArrayJsonItem;
41      range.Start = cdata.Value[0];
42      range.End = cdata.Value[1];
43    }
44
45    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
46      DoubleRange range = value as DoubleRange;
47      return new DoubleArrayJsonItem() {
48        Name = "[OverridableParamName]",
49        Value = new double[] { range.Start, range.End },
50        Range = new double[] { double.MinValue, double.MaxValue }
51      };
52    }
53  }
54}
Note: See TracBrowser for help on using the repository browser.