Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/JsonItemVMBase.cs @ 17411

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

#3026:

  • deleted JsonItemVM
  • reduced code duplicates in JsonItemValueControl
  • implemented logic for entering ranges -> automatically sets to min/max value of datatype when checkbox is not checked
File size: 1.9 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  public class JsonItemVMBase : INotifyPropertyChanged {
10    public event PropertyChangedEventHandler PropertyChanged;
11    public IJsonItem Item { get; set; }
12
13    protected void OnPropertyChange(object sender, string propertyName) {
14      // Make a temporary copy of the event to avoid possibility of
15      // a race condition if the last subscriber unsubscribes
16      // immediately after the null check and before the event is raised.
17      // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/events/how-to-raise-base-class-events-in-derived-classes
18     
19      PropertyChangedEventHandler tmp = PropertyChanged;
20      tmp?.Invoke(this, new PropertyChangedEventArgs(propertyName));
21    }
22
23    public virtual Type JsonItemType => typeof(JsonItem);
24
25    //protected IJsonItemValueParser Parser { get; set; }
26    //child tree
27    //private IList<JsonItemVM> nodes = new List<JsonItemVM>();
28
29    //public IEnumerable<JsonItemVM> Nodes { get => nodes; }
30    //public JsonItemVM Parent { get; private set; }
31
32
33    private bool selected = true;
34    public bool Selected {
35      get => selected;
36      set {
37        selected = value;
38        OnPropertyChange(this, nameof(Selected));
39      }
40    }
41
42    public string Name {
43      get => Item.Name;
44      set {
45        Item.Name = value;
46        OnPropertyChange(this, nameof(Name));
47      }
48    }
49
50    public string ActualName {
51      get => Item.ActualName;
52      set {
53        Item.ActualName = value;
54        OnPropertyChange(this, nameof(ActualName));
55      }
56    }
57    public virtual JsonItemBaseControl GetControl() {
58      return new JsonItemBaseControl(this);
59    }
60
61  }
62}
Note: See TracBrowser for help on using the repository browser.