/// <summary> /// Initializes a new instance of the <see cref="Command{T}" /> class. /// </summary> /// <param name="execute">The execution method.</param> /// <param name="canExecute">The function to test whether the <paramref name="execute" /> method may be invoked.</param> /// <param name="options">The options.</param> /// <exception cref="ArgumentNullException"><paramref name="execute" /> is <c>null</c>.</exception> public Command([NotNull] Action <T, CancellationToken> execute, Func <T, bool> canExecute = null, CommandOptions options = null) : base(false, canExecute, options ?? CommandOptions.Default) { if (execute == null) { throw new ArgumentNullException(nameof(execute)); } this.execute = (arg, _, cancellationToken) => execute(arg, cancellationToken); }
/// <summary> /// Initializes a new instance of the <see cref="Command{T}" /> class. /// </summary> /// <param name="execute">The execution method.</param> /// <param name="canExecute">The function to test whether the <paramref name="execute" /> method may be invoked.</param> /// <param name="options">The options.</param> /// <exception cref="ArgumentNullException"><paramref name="execute" /> is <c>null</c>.</exception> public Command( [NotNull] Action <T, CommandExecutionController, CancellationToken> execute, Func <T, bool> canExecute = null, CommandOptions options = null) : base(false, canExecute, options ?? CommandOptions.Default) => this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
internal ParameterizedCommand(bool isThreadSafe, Func <T, bool> canExecute, [NotNull] CommandOptions options) : base(isThreadSafe, options) => this.canExecute = canExecute;
internal CommandBase(bool isThreadSafe, [NotNull] CommandOptions options) : base(isThreadSafe) => Options = options;
/// <summary> /// Initializes a new instance of the <see cref="AsyncCommand" /> class. /// </summary> /// <param name="execute">The execution method.</param> /// <param name="canExecute">The function to test whether the <paramref name="execute" /> method may be invoked.</param> /// <param name="options">The options.</param> /// <exception cref="ArgumentNullException"><paramref name="execute" /> is <c>null</c>.</exception> public AsyncCommand( [NotNull] Func <CommandExecutionController, CancellationToken, Task> execute, Func <bool> canExecute = null, CommandOptions options = null) : base(true, canExecute, options ?? CommandOptions.DefaultAsync) => this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
/// <summary> /// Initializes a new instance of the <see cref="AsyncCommand" /> class. /// </summary> /// <param name="execute">The execution method.</param> /// <param name="canExecute">The function to test whether the <paramref name="execute" /> method may be invoked.</param> /// <param name="options">The options.</param> /// <exception cref="ArgumentNullException"><paramref name="execute" /> is <c>null</c>.</exception> public AsyncCommand([NotNull] Func <CancellationToken, Task> execute, Func <bool> canExecute = null, CommandOptions options = null) : base(true, canExecute, options ?? CommandOptions.DefaultAsync) { if (execute == null) { throw new ArgumentNullException(nameof(execute)); } this.execute = (_, cancellationToken) => execute(cancellationToken); }
/// <summary> /// Initializes a new instance of the <see cref="AsyncCommand{T}" /> class. /// </summary> /// <param name="execute">The execution method.</param> /// <param name="canExecute">The function to test whether the <paramref name="execute" /> method may be invoked.</param> /// <param name="options">The options.</param> /// <exception cref="ArgumentNullException"><paramref name="execute" /> is <c>null</c>.</exception> public AsyncCommand([NotNull] Func <T, Task> execute, Func <T, bool> canExecute = null, CommandOptions options = null) : base(true, canExecute, options ?? CommandOptions.DefaultAsync) { if (execute == null) { throw new ArgumentNullException(nameof(execute)); } this.execute = (arg, _, __) => execute(arg); }