Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/RangeVM.cs @ 17444

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

#3026:

  • refactored ranged based VMs -> created new 'base' class for ranged based VMs RangedValueBaseVM
  • renamed AddChilds to AddChildren
  • implemented ArrayValueVM and JsonItemArrayValueControl
  • added ranges for array and matrix values
File size: 1.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace HeuristicLab.JsonInterface.OptimizerIntegration {
9
10  public class IntRangeVM : RangeVM<int> {
11    public override Type JsonItemType => typeof(IntRangeJsonItem);
12
13    protected override int MinTypeValue => int.MinValue;
14
15    protected override int MaxTypeValue => int.MaxValue;
16
17    public override JsonItemBaseControl GetControl() =>
18      new JsonItemRangeControl(this);
19  }
20
21  public class DoubleRangeVM : RangeVM<double> {
22    public override Type JsonItemType => typeof(DoubleRangeJsonItem);
23
24    protected override double MinTypeValue => double.MinValue;
25
26    protected override double MaxTypeValue => double.MaxValue;
27
28    public override JsonItemBaseControl GetControl() =>
29      new JsonItemRangeControl(this);
30  }
31
32  public abstract class RangeVM<T> : RangedValueBaseVM<T> {
33
34    public T MinValue {
35      get => Cast(((Array)Item.Value).GetValue(0));
36      set {
37        SetValue(value, ((Array)Item.Value).GetValue(1));
38        OnPropertyChange(this, nameof(MinValue));
39      }
40    }
41
42    public T MaxValue {
43      get => Cast(((Array)Item.Value).GetValue(1));
44      set {
45        SetValue(((Array)Item.Value).GetValue(0), value);
46        OnPropertyChange(this, nameof(MaxValue));
47      }
48    }
49
50    private void SetValue(object min, object max) =>
51      Item.Value = new object[] { min, max };
52  }
53}
Note: See TracBrowser for help on using the repository browser.