main
1using System;
2using System.ComponentModel;
3using solidware.financials.windows.ui.presenters.validation;
4
5namespace solidware.financials.windows.ui.views.controls
6{
7 public class ObservableProperty<T> : Observable<T>, IDataErrorInfo
8 {
9 T value;
10
11 public ObservableProperty() : this(default(T)) {}
12
13 public ObservableProperty(T value)
14 {
15 this.value = value;
16 Notification = new Notification<Observable<T>>();
17 }
18
19 public Notification<Observable<T>> Notification { get; private set; }
20
21 public T Value
22 {
23 get { return value; }
24 set
25 {
26 this.value = value;
27 PropertyChanged(this, new PropertyChangedEventArgs("Value"));
28 }
29 }
30
31 public void WhenChanged(Action observer)
32 {
33 PropertyChanged += (o, e) => observer();
34 }
35
36 public void Register<TSeverity>(Func<T, bool> failCondition, Func<string> errorMessage) where TSeverity : Severity, new()
37 {
38 Notification.Register<TSeverity>(x => x.Value, () => failCondition(Value), errorMessage);
39 }
40
41 object Observable.Value
42 {
43 get { return value; }
44 }
45
46 static public implicit operator T(ObservableProperty<T> val)
47 {
48 return val.value;
49 }
50
51 public event PropertyChangedEventHandler PropertyChanged = (o, e) => {};
52
53 public override string ToString()
54 {
55 return value.ToString();
56 }
57
58 public string this[string property]
59 {
60 get { return Notification[property]; }
61 }
62
63 public string Error
64 {
65 get { throw new NotImplementedException(); }
66 }
67 }
68}