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
137 lines (122 loc) · 5.15 KB
/
ReactiveObject.cs
File metadata and controls
137 lines (122 loc) · 5.15 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
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<ReactiveObject>, IHandleObservableErrors, IReactiveObject
{
public event PropertyChangingEventHandler PropertyChanging {
add { PropertyChangingEventManager.AddHandler(this, value); }
remove { PropertyChangingEventManager.RemoveHandler(this, value); }
}
void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args)
{
PropertyChangingEventManager.DeliverEvent(this, args);
}
public event PropertyChangedEventHandler PropertyChanged {
add { PropertyChangedEventManager.AddHandler(this, value); }
remove { PropertyChangedEventManager.RemoveHandler(this, value); }
}
void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args)
{
PropertyChangedEventManager.DeliverEvent(this, args);
}
/// <summary>
/// Represents an Observable that fires *before* a property is about to
/// be changed.
/// </summary>
[IgnoreDataMember]
public IObservable<IObservedChange<ReactiveObject, object>> Changing {
get { return this.getChangingObservable(); }
}
/// <summary>
/// Represents an Observable that fires *after* a property has changed.
/// </summary>
[IgnoreDataMember]
public IObservable<IObservedChange<ReactiveObject, object>> Changed {
get { return this.getChangedObservable(); }
}
[IgnoreDataMember]
public IObservable<Exception> ThrownExceptions { get { return this.getThrownExceptionsObservable(); } }
protected ReactiveObject()
{
}
public IDisposable SuppressChangeNotifications() {
return this.suppressChangeNotifications();
}
public bool AreChangeNotificationsEnabled() {
return this.areChangeNotificationsEnabled();
}
}
}
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 :