forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReactiveObject.cs
More file actions
141 lines (124 loc) · 5.04 KB
/
ReactiveObject.cs
File metadata and controls
141 lines (124 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Reactive.Disposables;
using System.Linq;
using System.Linq.Expressions;
using System.Reactive.Subjects;
using System.Reflection;
using System.Runtime.Serialization;
using System.Threading;
using System.Reactive.Concurrency;
using System.Runtime.CompilerServices;
using Splat;
namespace ReactiveUI
{
/// <summary>
/// ReactiveObject is the base object for ViewModel classes, and it
/// implements INotifyPropertyChanged. In addition, ReactiveObject provides
/// Changing and Changed Observables to monitor object changes.
/// </summary>
[DataContract]
public class ReactiveObject : IReactiveNotifyPropertyChanged, IHandleObservableErrors, IReactiveObjectExtension
{
[field:IgnoreDataMember]
public event PropertyChangingEventHandler PropertyChanging;
void IReactiveObjectExtension.RaisePropertyChanging(PropertyChangingEventArgs args)
{
var handler = PropertyChanging;
if (handler != null) {
handler(this, args);
}
}
[field:IgnoreDataMember]
public event PropertyChangedEventHandler PropertyChanged;
void IReactiveObjectExtension.RaisePropertyChanged(PropertyChangedEventArgs args)
{
var handler = PropertyChanged;
if (handler != null) {
handler(this, args);
}
}
/// <summary>
/// Represents an Observable that fires *before* a property is about to
/// be changed.
/// </summary>
[IgnoreDataMember]
public IObservable<IObservedChange<object, object>> Changing {
get { return this.getChangingObservable(); }
}
/// <summary>
/// Represents an Observable that fires *after* a property has changed.
/// </summary>
[IgnoreDataMember]
public IObservable<IObservedChange<object, object>> Changed {
get { return this.getChangedObservable(); }
}
[IgnoreDataMember]
public IObservable<Exception> ThrownExceptions { get { return this.getThrownExceptionsObservable(); } }
protected ReactiveObject()
{
this.setupReactiveExtension();
}
[OnDeserialized]
void setupRxObj(StreamingContext sc) { this.setupReactiveExtension(); }
public IDisposable SuppressChangeNotifications() {
return this.suppressChangeNotifications();
}
}
}
namespace ReactiveUI.Testing
{
public static class ReactiveObjectTestMixin
{
/// <summary>
/// RaisePropertyChanging is a helper method intended for test / mock
/// scenarios to manually fake a property change.
/// </summary>
/// <param name="target">The ReactiveObject to invoke
/// raisePropertyChanging on.</param>
/// <param name="property">The property that will be faking a change.</param>
public static void RaisePropertyChanging(ReactiveObject target, string property)
{
target.raisePropertyChanging(property);
}
/// <summary>
/// RaisePropertyChanging is a helper method intended for test / mock
/// scenarios to manually fake a property change.
/// </summary>
/// <param name="target">The ReactiveObject to invoke
/// raisePropertyChanging on.</param>
/// <param name="property">The property that will be faking a change.</param>
public static void RaisePropertyChanging<TSender, TValue>(TSender target, Expression<Func<TSender, TValue>> property)
where TSender : ReactiveObject
{
RaisePropertyChanging(target, Reflection.SimpleExpressionToPropertyName(property));
}
/// <summary>
/// RaisePropertyChanged is a helper method intended for test / mock
/// scenarios to manually fake a property change.
/// </summary>
/// <param name="target">The ReactiveObject to invoke
/// raisePropertyChanging on.</param>
/// <param name="property">The property that will be faking a change.</param>
public static void RaisePropertyChanged(ReactiveObject target, string property)
{
target.raisePropertyChanged(property);
}
/// <summary>
/// RaisePropertyChanged is a helper method intended for test / mock
/// scenarios to manually fake a property change.
/// </summary>
/// <param name="target">The ReactiveObject to invoke
/// raisePropertyChanging on.</param>
/// <param name="property">The property that will be faking a change.</param>
public static void RaisePropertyChanged<TSender, TValue>(TSender target, Expression<Func<TSender, TValue>> property)
where TSender : ReactiveObject
{
RaisePropertyChanged(target, Reflection.SimpleExpressionToPropertyName(property));
}
}
}
// vim: tw=120 ts=4 sw=4 et :