From 751ab52783744679da89df310903149146a82ee6 Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Wed, 22 Nov 2023 08:48:21 +0000 Subject: [PATCH] Option 2 Fix For #3644 --- ...valTests.ReactiveUI.DotNet6_0.verified.txt | 26 +--- ...valTests.ReactiveUI.DotNet7_0.verified.txt | 26 +--- ...provalTests.ReactiveUI.Net4_7.verified.txt | 26 +--- .../Bindings/Command/CommandBinder.cs | 118 +---------------- .../Command/CommandBinderImplementation.cs | 119 ------------------ .../CommandBinderImplementationMixins.cs | 39 +----- .../Command/ICommandBinderImplementation.cs | 54 +------- 7 files changed, 15 insertions(+), 393 deletions(-) diff --git a/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.DotNet6_0.verified.txt b/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.DotNet6_0.verified.txt index 428d21b6ba..63c4473be6 100644 --- a/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.DotNet6_0.verified.txt +++ b/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.DotNet6_0.verified.txt @@ -81,26 +81,14 @@ namespace ReactiveUI public static class CommandBinder { public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.IObservable withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommandNonGeneric(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommandNonGeneric(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.IObservable withParameter, string? toEvent = null) + public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.IObservable withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommandNonGeneric(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) + public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } @@ -109,18 +97,10 @@ namespace ReactiveUI { public CommandBinderImplementation() { } public ReactiveUI.IReactiveBinding BindCommand(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.IObservable withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public ReactiveUI.IReactiveBinding BindCommand(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public ReactiveUI.IReactiveBinding BindCommandNonGeneric(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.IObservable withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } - public ReactiveUI.IReactiveBinding BindCommandNonGeneric(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) + public ReactiveUI.IReactiveBinding BindCommand(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } diff --git a/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.DotNet7_0.verified.txt b/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.DotNet7_0.verified.txt index a0cc917fca..89ea095473 100644 --- a/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.DotNet7_0.verified.txt +++ b/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.DotNet7_0.verified.txt @@ -81,26 +81,14 @@ namespace ReactiveUI public static class CommandBinder { public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.IObservable withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommandNonGeneric(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommandNonGeneric(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.IObservable withParameter, string? toEvent = null) + public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.IObservable withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommandNonGeneric(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) + public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } @@ -109,18 +97,10 @@ namespace ReactiveUI { public CommandBinderImplementation() { } public ReactiveUI.IReactiveBinding BindCommand(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.IObservable withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public ReactiveUI.IReactiveBinding BindCommand(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public ReactiveUI.IReactiveBinding BindCommandNonGeneric(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.IObservable withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } - public ReactiveUI.IReactiveBinding BindCommandNonGeneric(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) + public ReactiveUI.IReactiveBinding BindCommand(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } diff --git a/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.Net4_7.verified.txt b/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.Net4_7.verified.txt index 2e8f3eef9a..a08268e9a0 100644 --- a/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.Net4_7.verified.txt +++ b/src/ReactiveUI.Tests/Utilities/ApiApprovalTests.ReactiveUI.Net4_7.verified.txt @@ -79,26 +79,14 @@ namespace ReactiveUI public static class CommandBinder { public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.IObservable withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommandNonGeneric(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommandNonGeneric(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.IObservable withParameter, string? toEvent = null) + public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.IObservable withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } - public static ReactiveUI.IReactiveBinding BindCommandNonGeneric(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) + public static ReactiveUI.IReactiveBinding BindCommand(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression> propertyName, System.Linq.Expressions.Expression> controlName, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } @@ -107,18 +95,10 @@ namespace ReactiveUI { public CommandBinderImplementation() { } public ReactiveUI.IReactiveBinding BindCommand(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.IObservable withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public ReactiveUI.IReactiveBinding BindCommand(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) - where TView : class, ReactiveUI.IViewFor - where TViewModel : class - where TProp : System.Windows.Input.ICommand { } - public ReactiveUI.IReactiveBinding BindCommandNonGeneric(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.IObservable withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } - public ReactiveUI.IReactiveBinding BindCommandNonGeneric(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) + public ReactiveUI.IReactiveBinding BindCommand(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression> vmProperty, System.Linq.Expressions.Expression> controlProperty, System.Linq.Expressions.Expression> withParameter, string? toEvent = null) where TView : class, ReactiveUI.IViewFor where TViewModel : class where TProp : System.Windows.Input.ICommand { } diff --git a/src/ReactiveUI/Bindings/Command/CommandBinder.cs b/src/ReactiveUI/Bindings/Command/CommandBinder.cs index 915eb084be..9d278a66fc 100644 --- a/src/ReactiveUI/Bindings/Command/CommandBinder.cs +++ b/src/ReactiveUI/Bindings/Command/CommandBinder.cs @@ -44,39 +44,6 @@ static CommandBinder() /// NOTE: If this parameter is used inside WhenActivated, it's /// important to dispose the binding when the view is deactivated. public static IReactiveBinding BindCommand( - this TView view, - TViewModel? viewModel, - Expression> propertyName, - Expression> controlName, - IObservable withParameter, - string? toEvent = null) - where TView : class, IViewFor - where TViewModel : class - where TProp : ICommand => - _binderImplementation.BindCommand(viewModel, view, propertyName, controlName, withParameter, toEvent); - - /// - /// Bind a command from the ViewModel to an explicitly specified control - /// on the View. - /// - /// The view type. - /// The view model type. - /// The property type. - /// The control type. - /// The parameter type. - /// A class representing the binding. Dispose it to disconnect - /// the binding. - /// The View. - /// The View model. - /// The ViewModel command to bind. - /// The name of the control on the view. - /// The ViewModel property to pass as the - /// param of the ICommand. - /// If specified, bind to the specific event - /// instead of the default. - /// NOTE: If this parameter is used inside WhenActivated, it's - /// important to dispose the binding when the view is deactivated. - public static IReactiveBinding BindCommandNonGeneric( this TView view, TViewModel? viewModel, Expression> propertyName, @@ -86,7 +53,7 @@ public static IReactiveBinding BindCommandNonGeneric - _binderImplementation.BindCommandNonGeneric(viewModel, view, propertyName, controlName, withParameter, toEvent); + _binderImplementation.BindCommand(viewModel, view, propertyName, controlName, withParameter, toEvent); /// /// Bind a command from the ViewModel to an explicitly specified control @@ -107,35 +74,6 @@ public static IReactiveBinding BindCommandNonGeneric public static IReactiveBinding BindCommand( - this TView view, - TViewModel? viewModel, - Expression> propertyName, - Expression> controlName, - string? toEvent = null) - where TView : class, IViewFor - where TViewModel : class - where TProp : ICommand => - _binderImplementation.BindCommand(viewModel, view, propertyName, controlName, toEvent); - - /// - /// Bind a command from the ViewModel to an explicitly specified control - /// on the View. - /// - /// The view type. - /// The view model type. - /// The property type. - /// The control type. - /// A class representing the binding. Dispose it to disconnect - /// the binding. - /// The View. - /// The View model. - /// The ViewModel command to bind. - /// The name of the control on the view. - /// If specified, bind to the specific event - /// instead of the default. - /// NOTE: If this parameter is used inside WhenActivated, it's - /// important to dispose the binding when the view is deactivated. - public static IReactiveBinding BindCommandNonGeneric( this TView view, TViewModel? viewModel, Expression> propertyName, @@ -144,7 +82,7 @@ public static IReactiveBinding BindCommandNonGeneric - _binderImplementation.BindCommandNonGeneric(viewModel, view, propertyName, controlName, toEvent); + _binderImplementation.BindCommand(viewModel, view, propertyName, controlName, toEvent); /// /// Bind a command from the ViewModel to an explicitly specified control @@ -168,56 +106,6 @@ public static IReactiveBinding BindCommandNonGeneric public static IReactiveBinding BindCommand( - this TView view, - TViewModel? viewModel, - Expression> propertyName, - Expression> controlName, - Expression> withParameter, - string? toEvent = null) - where TView : class, IViewFor - where TViewModel : class - where TProp : ICommand - { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(view); -#else - if (view is null) - { - throw new ArgumentNullException(nameof(view)); - } -#endif - - return _binderImplementation.BindCommand( - viewModel, - view, - propertyName, - controlName, - withParameter, - toEvent); - } - - /// - /// Bind a command from the ViewModel to an explicitly specified control - /// on the View. - /// - /// The view type. - /// The view model type. - /// The property type. - /// The control type. - /// The parameter type. - /// A class representing the binding. Dispose it to disconnect - /// the binding. - /// The View. - /// The View model. - /// The ViewModel command to bind. - /// The name of the control on the view. - /// The ViewModel property to pass as the - /// param of the ICommand. - /// If specified, bind to the specific event - /// instead of the default. - /// NOTE: If this parameter is used inside WhenActivated, it's - /// important to dispose the binding when the view is deactivated. - public static IReactiveBinding BindCommandNonGeneric( this TView view, TViewModel? viewModel, Expression> propertyName, @@ -237,7 +125,7 @@ public static IReactiveBinding BindCommandNonGeneric public IReactiveBinding BindCommand( - TViewModel? viewModel, - TView view, - Expression> vmProperty, - Expression> controlProperty, - Expression> withParameter, - string? toEvent = null) - where TView : class, IViewFor - where TViewModel : class - where TProp : ICommand - { - if (vmProperty is null) - { - throw new ArgumentNullException(nameof(vmProperty)); - } - - if (controlProperty is null) - { - throw new ArgumentNullException(nameof(controlProperty)); - } - - var vmExpression = Reflection.Rewrite(vmProperty.Body); - var controlExpression = Reflection.Rewrite(controlProperty.Body); - var source = Reflection.ViewModelWhenAnyValue(viewModel, view, vmExpression).Cast(); - - var bindingDisposable = BindCommandInternal(source, view, controlExpression, withParameter.ToObservable(viewModel), toEvent); - - return new ReactiveBinding( - view, - controlExpression, - vmExpression, - source, - BindingDirection.OneWay, - bindingDisposable); - } - - /// - /// Bind a command from the ViewModel to an explicitly specified control - /// on the View. - /// - /// The view type. - /// The view model type. - /// The property type. - /// The control type. - /// The parameter type. - /// The View model. - /// The View. - /// The ViewModel command to bind. - /// The name of the control on the view. - /// The ViewModel property to pass as the - /// param of the ICommand. - /// If specified, bind to the specific event - /// instead of the default. - /// NOTE: If this parameter is used inside WhenActivated, it's - /// important to dispose the binding when the view is deactivated. - /// - /// A class representing the binding. Dispose it to disconnect - /// the binding. - /// - /// nameof(vmProperty) - /// or - /// nameof(vmProperty). - public IReactiveBinding BindCommandNonGeneric( TViewModel? viewModel, TView view, Expression> vmProperty, @@ -158,63 +96,6 @@ public IReactiveBinding BindCommandNonGeneric public IReactiveBinding BindCommand( - TViewModel? viewModel, - TView view, - Expression> vmProperty, - Expression> controlProperty, - IObservable withParameter, - string? toEvent = null) - where TView : class, IViewFor - where TViewModel : class - where TProp : ICommand - { - if (vmProperty is null) - { - throw new ArgumentNullException(nameof(vmProperty)); - } - - if (controlProperty is null) - { - throw new ArgumentNullException(nameof(controlProperty)); - } - - var vmExpression = Reflection.Rewrite(vmProperty.Body); - var controlExpression = Reflection.Rewrite(controlProperty.Body); - var source = Reflection.ViewModelWhenAnyValue(viewModel, view, vmExpression).Cast(); - - var bindingDisposable = BindCommandInternal(source, view, controlExpression, withParameter, toEvent); - - return new ReactiveBinding( - view, - controlExpression, - vmExpression, - source, - BindingDirection.OneWay, - bindingDisposable); - } - - /// - /// Bind a command from the ViewModel to an explicitly specified control - /// on the View. - /// - /// The view type. - /// The view model type. - /// The property type. - /// The control type. - /// The parameter type. - /// A class representing the binding. Dispose it to disconnect - /// the binding. - /// The View model. - /// The View. - /// The ViewModel command to bind. - /// The name of the control on the view. - /// The ViewModel property to pass as the - /// param of the ICommand. - /// If specified, bind to the specific event - /// instead of the default. - /// NOTE: If this parameter is used inside WhenActivated, it's - /// important to dispose the binding when the view is deactivated. - public IReactiveBinding BindCommandNonGeneric( TViewModel? viewModel, TView view, Expression> vmProperty, diff --git a/src/ReactiveUI/Bindings/Command/CommandBinderImplementationMixins.cs b/src/ReactiveUI/Bindings/Command/CommandBinderImplementationMixins.cs index 1ad482159f..5223efea68 100644 --- a/src/ReactiveUI/Bindings/Command/CommandBinderImplementationMixins.cs +++ b/src/ReactiveUI/Bindings/Command/CommandBinderImplementationMixins.cs @@ -19,47 +19,12 @@ public static IReactiveBinding BindCommand> propertyName, Expression> controlName, string? toEvent = null) - where TView : class, IViewFor + where TView : class, IViewFor where TViewModel : class where TProp : ICommand => @this.BindCommand(viewModel, view, propertyName, controlName, Observable.Empty, toEvent); public static IReactiveBinding BindCommand( - this ICommandBinderImplementation @this, - TViewModel? viewModel, - TView view, - Expression> propertyName, - Expression> controlName, - Expression> withParameter, - string? toEvent = null) - where TView : class, IViewFor - where TViewModel : class - where TProp : ICommand - { - if (withParameter is null) - { - throw new ArgumentNullException(nameof(withParameter)); - } - - var paramExpression = Reflection.Rewrite(withParameter.Body); - var param = Reflection.ViewModelWhenAnyValue(viewModel, view, paramExpression); - - return @this.BindCommand(viewModel, view, propertyName, controlName, param, toEvent); - } - - public static IReactiveBinding BindCommandNonGeneric( - this ICommandBinderImplementation @this, - TViewModel? viewModel, - TView view, - Expression> propertyName, - Expression> controlName, - string? toEvent = null) - where TView : class, IViewFor - where TViewModel : class - where TProp : ICommand => - @this.BindCommandNonGeneric(viewModel, view, propertyName, controlName, Observable.Empty, toEvent); - - public static IReactiveBinding BindCommandNonGeneric( this ICommandBinderImplementation @this, TViewModel? viewModel, TView view, @@ -79,6 +44,6 @@ public static IReactiveBinding BindCommandNonGenericThe type of the parameter to pass to the ICommand. /// A reactive binding. Often only used for disposing the binding. IReactiveBinding BindCommand( - TViewModel? viewModel, - TView view, - Expression> vmProperty, - Expression> controlProperty, - Expression> withParameter, - string? toEvent = null) - where TView : class, IViewFor - where TViewModel : class - where TProp : ICommand; - - /// - /// Binds the command on a ViewModel to a control on the View. - /// - /// The view model to bind to. - /// The view to bind to. - /// The name of the property on the View Model. - /// The name of the control on the View. - /// A observable if we want to pass a parameter to the ICommand. - /// A event on the view that will also trigger the command. - /// The type of the view. - /// The type of the view model. - /// The type of the property on the view model. - /// The type of control on the view. - /// The type of the parameter to pass to the ICommand. - /// A reactive binding. Often only used for disposing the binding. - IReactiveBinding BindCommand( - TViewModel? viewModel, - TView view, - Expression> vmProperty, - Expression> controlProperty, - IObservable withParameter, - string? toEvent = null) - where TView : class, IViewFor - where TViewModel : class - where TProp : ICommand; - - /// - /// Binds the command on a ViewModel to a control on the View. - /// - /// The view model to bind to. - /// The view to bind to. - /// The name of the property on the View Model. - /// The name of the control on the View. - /// A function if we want to pass a parameter to the ICommand. - /// A event on the view that will also trigger the command. - /// The type of the view. - /// The type of the view model. - /// The type of the property on the view model. - /// The type of control on the view. - /// The type of the parameter to pass to the ICommand. - /// A reactive binding. Often only used for disposing the binding. - IReactiveBinding BindCommandNonGeneric( TViewModel? viewModel, TView view, Expression> vmProperty, @@ -105,7 +53,7 @@ IReactiveBinding BindCommandNonGenericThe type of control on the view. /// The type of the parameter to pass to the ICommand. /// A reactive binding. Often only used for disposing the binding. - IReactiveBinding BindCommandNonGeneric( + IReactiveBinding BindCommand( TViewModel? viewModel, TView view, Expression> vmProperty,