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
122 lines (106 loc) · 3.93 KB
/
ReactiveObject.cs
File metadata and controls
122 lines (106 loc) · 3.93 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.
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<IReactiveObject>, IHandleObservableErrors, IReactiveObject
{
#if NET_45
public event PropertyChangingEventHandler PropertyChanging;
void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args)
{
var handler = this.PropertyChanging;
if(handler != null) {
handler(this, args);
}
}
public event PropertyChangedEventHandler PropertyChanged;
void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args)
{
var handler = this.PropertyChanged;
if (handler != null) {
handler(this, args);
}
}
#else
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);
}
#endif
/// <summary>
/// Represents an Observable that fires *before* a property is about to
/// be changed.
/// </summary>
[IgnoreDataMember]
public IObservable<IReactivePropertyChangedEventArgs<IReactiveObject>> Changing {
get { return ((IReactiveObject) this).getChangingObservable(); }
}
/// <summary>
/// Represents an Observable that fires *after* a property has changed.
/// </summary>
[IgnoreDataMember]
public IObservable<IReactivePropertyChangedEventArgs<IReactiveObject>> Changed {
get { return ((IReactiveObject) this).getChangedObservable(); }
}
/// <summary>
///
/// </summary>
[IgnoreDataMember]
public IObservable<Exception> ThrownExceptions { get { return this.getThrownExceptionsObservable(); } }
protected ReactiveObject()
{
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public IDisposable SuppressChangeNotifications() {
return this.suppressChangeNotifications();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool AreChangeNotificationsEnabled() {
return this.areChangeNotificationsEnabled();
}
public IDisposable DelayChangeNotifications() {
return this.delayChangeNotifications();
}
}
}
// vim: tw=120 ts=4 sw=4 et :