Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/RangedValueBaseVM.cs @ 17446

Last change on this file since 17446 was 17420, checked in by dpiringe, 5 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.6 KB
RevLine 
[17420]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace HeuristicLab.JsonInterface.OptimizerIntegration {
8  public abstract class RangedValueBaseVM : RangedValueBaseVM<object> { }
9
10  public abstract class RangedValueBaseVM<T> : JsonItemVMBase {
11    public T MinRange {
12      get => Cast(Item.Range?.First());
13      set {
14        SetRange(value, Item.Range?.Last());
15        OnPropertyChange(this, nameof(MinRange));
16      }
17    }
18
19    public T MaxRange {
20      get => Cast(Item.Range?.Last());
21      set {
22        SetRange(Item.Range?.First(), value);
23        OnPropertyChange(this, nameof(MaxRange));
24      }
25    }
26
27    private bool enableMinRange = false;
28    public bool EnableMinRange {
29      get => enableMinRange;
30      set {
31        enableMinRange = value;
32        if (!enableMinRange)
33          MinRange = MinTypeValue;
34        OnPropertyChange(this, nameof(EnableMinRange));
35      }
36    }
37
38    private bool enableMaxRange = false;
39    public bool EnableMaxRange {
40      get => enableMaxRange;
41      set {
42        enableMaxRange = value;
43        if (!enableMaxRange)
44          MaxRange = MaxTypeValue;
45        OnPropertyChange(this, nameof(EnableMaxRange));
46      }
47    }
48
49    protected T Cast(object obj) => (obj==null) ? default(T) : (T)Convert.ChangeType(obj, typeof(T));
50
51    private void SetRange(object min, object max) {
52      object[] range = new object[] { min, max };
53      Item.Range = range;
54    }
55
56    protected abstract T MinTypeValue { get; }
57    protected abstract T MaxTypeValue { get; }
58  }
59}
Note: See TracBrowser for help on using the repository browser.