/// <summary>
 /// A utility method that will pipe an Observable to an ICommand (i.e.
 /// it will first call its CanExecute with the provided value, then if
 /// the command can be executed, Execute() will be called).
 /// </summary>
 /// <typeparam name="T">The type.</typeparam>
 /// <typeparam name="TResult">The result type.</typeparam>
 /// <param name="this">The source observable to pipe into the command.</param>
 /// <param name="command">The command to be executed.</param>
 /// <returns>An object that when disposes, disconnects the Observable
 /// from the command.</returns>
 public static IDisposable InvokeCommand <T, TResult>(this IObservable <T> @this, ReactiveCommandBase <T, TResult> command)
 {
     return(WithLatestFromFixed(@this, command.CanExecute, (value, canExecute) => InvokeCommandInfo.From(command, canExecute, value))
            .Where(ii => ii.CanExecute)
            .SelectMany(ii => command.Execute(ii.Value).Catch(Observable <TResult> .Empty))
            .Subscribe());
 }
Beispiel #2
0
        /// <summary>
        /// A utility method that will pipe an Observable to an ICommand (i.e.
        /// it will first call its CanExecute with the provided value, then if
        /// the command can be executed, Execute() will be called).
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <typeparam name="TResult">The result type.</typeparam>
        /// <param name="item">The source observable to pipe into the command.</param>
        /// <param name="command">The command to be executed.</param>
        /// <returns>An object that when disposes, disconnects the Observable
        /// from the command.</returns>
        public static IDisposable InvokeCommand <T, TResult>(this IObservable <T> item, ReactiveCommandBase <T, TResult> command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            return(WithLatestFromFixed(item, command.CanExecute, (value, canExecute) => InvokeCommandInfo.From(command, canExecute, value))
                   .Where(ii => ii.CanExecute)
                   .SelectMany(ii => command.Execute(ii.Value).Catch(Observable <TResult> .Empty))
                   .Subscribe());
        }
 /// <summary>
 /// A utility method that will pipe an Observable to an ICommand (i.e.
 /// it will first call its CanExecute with the provided value, then if
 /// the command can be executed, Execute() will be called).
 /// </summary>
 /// <typeparam name="T">The type.</typeparam>
 /// <typeparam name="TResult">The result type.</typeparam>
 /// <param name="item">The source observable to pipe into the command.</param>
 /// <param name="command">The command to be executed.</param>
 /// <returns>An object that when disposes, disconnects the Observable
 /// from the command.</returns>
 public static IDisposable InvokeCommand <T, TResult>(this IObservable <T> item, ReactiveCommandBase <T, TResult>?command) =>
 command is null
         ? throw new ArgumentNullException(nameof(command))