diff --git a/ReactiveUI.Tests/Android/PropertyBindingTestViews.cs b/ReactiveUI.Tests/Android/PropertyBindingTestViews.cs index 00414fe5c9..fac5ddc805 100644 --- a/ReactiveUI.Tests/Android/PropertyBindingTestViews.cs +++ b/ReactiveUI.Tests/Android/PropertyBindingTestViews.cs @@ -9,7 +9,6 @@ using Android.App; using Android.Widget; using Android.Content; -using ReactiveUI.Android; using Xunit; namespace ReactiveUI.Tests diff --git a/ReactiveUI/ReactiveCommand.cs b/ReactiveUI/ReactiveCommand.cs index 13e20dd997..412ed78e26 100644 --- a/ReactiveUI/ReactiveCommand.cs +++ b/ReactiveUI/ReactiveCommand.cs @@ -281,6 +281,31 @@ public static ReactiveCommand CreateCombined(params IReactiveCommand[] c /// public class ReactiveCommand : IReactiveCommand, IReactiveCommand { +#if NET_45 + public event EventHandler CanExecuteChanged; + + protected virtual void raiseCanExecuteChanged(EventArgs args) + { + var handler = this.CanExecuteChanged; + if (handler != null) { + handler(this, args); + } + } +#else + public event EventHandler CanExecuteChanged + { + add { + if (canExecuteDisp == null) canExecuteDisp = canExecute.Connect(); + CanExecuteChangedEventManager.AddHandler(this, value); + } + remove { CanExecuteChangedEventManager.RemoveHandler(this, value); } + } + + protected virtual void raiseCanExecuteChanged(EventArgs args) + { + CanExecuteChangedEventManager.DeliverEvent(this, args); + } +#endif readonly Subject executeResults = new Subject(); readonly Subject isExecuting = new Subject(); readonly Func> executeAsync; @@ -310,7 +335,7 @@ public ReactiveCommand(IObservable canExecute, Func canExecuteLatest = x; if (fireCanExecuteChanged) { - CanExecuteChangedEventManager.DeliverEvent(this, EventArgs.Empty); + this.raiseCanExecuteChanged(EventArgs.Empty); } }) .Publish(); @@ -419,15 +444,6 @@ public bool CanExecute(object parameter) return canExecuteLatest; } - public event EventHandler CanExecuteChanged - { - add { - if (canExecuteDisp == null) canExecuteDisp = canExecute.Connect(); - CanExecuteChangedEventManager.AddHandler(this, value); - } - remove { CanExecuteChangedEventManager.RemoveHandler(this, value); } - } - public void Execute(object parameter) { ExecuteAsync(parameter).Subscribe(); diff --git a/ReactiveUI/ReactiveList.cs b/ReactiveUI/ReactiveList.cs index 0945d65a4c..5c9dface8f 100644 --- a/ReactiveUI/ReactiveList.cs +++ b/ReactiveUI/ReactiveList.cs @@ -23,6 +23,47 @@ namespace ReactiveUI [DebuggerTypeProxy(typeof(CollectionDebugView<>))] public class ReactiveList : IReactiveList, IReadOnlyReactiveList, IList { +#if NET_45 + public event NotifyCollectionChangedEventHandler CollectionChanging; + + protected virtual void raiseCollectionChanging(NotifyCollectionChangedEventArgs args) + { + var handler = this.CollectionChanging; + if (handler != null) { + handler(this, args); + } + } + + public event NotifyCollectionChangedEventHandler CollectionChanged; + + protected virtual void raiseCollectionChanged(NotifyCollectionChangedEventArgs args) + { + var handler = this.CollectionChanged; + if (handler != null) { + handler(this, args); + } + } + + 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 NotifyCollectionChangedEventHandler CollectionChanging { add { CollectionChangingEventManager.AddHandler(this, value); } remove { CollectionChangingEventManager.RemoveHandler(this, value); } @@ -32,6 +73,16 @@ public event NotifyCollectionChangedEventHandler CollectionChanged { add { CollectionChangedEventManager.AddHandler(this, value); } remove { CollectionChangedEventManager.RemoveHandler(this, value); } } + + protected virtual void raiseCollectionChanging(NotifyCollectionChangedEventArgs e) + { + CollectionChangingEventManager.DeliverEvent(this, e); + } + + protected virtual void raiseCollectionChanged(NotifyCollectionChangedEventArgs e) + { + CollectionChangedEventManager.DeliverEvent(this, e); + } public event PropertyChangingEventHandler PropertyChanging { @@ -53,6 +104,7 @@ void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args) { PropertyChangedEventManager.DeliverEvent(this, args); } +#endif [IgnoreDataMember] Subject _changing; [IgnoreDataMember] Subject _changed; @@ -634,16 +686,6 @@ static IObservable refcountSubscribers(IObservable input, Acti }); } - protected virtual void raiseCollectionChanging(NotifyCollectionChangedEventArgs e) - { - CollectionChangingEventManager.DeliverEvent(this, e); - } - - protected virtual void raiseCollectionChanged(NotifyCollectionChangedEventArgs e) - { - CollectionChangedEventManager.DeliverEvent(this, e); - } - #region Super Boring IList crap // The BinarySearch methods aren't technically on IList, they're implemented straight on List diff --git a/ReactiveUI/ReactiveObject.cs b/ReactiveUI/ReactiveObject.cs index 898c9785b5..da08f0ecea 100644 --- a/ReactiveUI/ReactiveObject.cs +++ b/ReactiveUI/ReactiveObject.cs @@ -24,6 +24,27 @@ namespace ReactiveUI [DataContract] public class ReactiveObject : IReactiveNotifyPropertyChanged, 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); } @@ -43,6 +64,7 @@ void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args) { PropertyChangedEventManager.DeliverEvent(this, args); } +#endif /// /// Represents an Observable that fires *before* a property is about to diff --git a/ReactiveUI/WeakEventManager.cs b/ReactiveUI/WeakEventManager.cs index def012de73..515f145267 100644 --- a/ReactiveUI/WeakEventManager.cs +++ b/ReactiveUI/WeakEventManager.cs @@ -11,25 +11,27 @@ namespace ReactiveUI { - public class CanExecuteChangedEventManager : WeakEventManager +#if !NET_45 + internal class CanExecuteChangedEventManager : WeakEventManager { } - public class PropertyChangingEventManager : WeakEventManager + internal class PropertyChangingEventManager : WeakEventManager { } - public class PropertyChangedEventManager : WeakEventManager + internal class PropertyChangedEventManager : WeakEventManager { } - public class CollectionChangingEventManager : WeakEventManager + internal class CollectionChangingEventManager : WeakEventManager { } - public class CollectionChangedEventManager : WeakEventManager + internal class CollectionChangedEventManager : WeakEventManager { } +#endif /// /// WeakEventManager base class. Inspired by the WPF WeakEventManager class and the code in