/// <summary> /// Initializes a new instance of the <see cref="DelegateCommand{TParam}"/> class. /// </summary> /// <param name="executeAction">The logic for <see cref="DelegateCommand{TParam}.OnExecute(TParam)" />.</param> /// <param name="canExecutePredicate">The logic for <see cref="DelegateCommand{TParam}.CanExecute(TParam)" />.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="executeAction" /> is <see langword="null" />. /// </exception> public DelegateCommand(ExecuteHandler executeAction, CanExecutePredicate canExecutePredicate) { if (executeAction == null) { throw new ArgumentNullException("executeAction"); } this._EXECUTE_ACTION = executeAction; this._CAN_EXECUTE_PREDICATE = canExecutePredicate ?? base.CanExecute; }
/// <summary> /// Initializes a new instance of the <see cref="DelegateJob" /> class. /// </summary> /// <param name="id">The ID of the job.</param> /// <param name="execAction">An action for a <see cref="DelegateJob.OnExecute(IJobExecutionContext)" /> method.</param> /// <param name="canExecutePredicate">A predicate for a <see cref="DelegateJob.OnCanExecute(DateTimeOffset, ref bool)" /> method.</param> /// <param name="isThreadSafe">Job schould work thread safe or not.</param> /// <param name="syncRoot">The object for thread safe operations.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="execAction" />, <paramref name="canExecutePredicate" /> and/or <paramref name="syncRoot" /> are <see langword="null" />. /// </exception> public DelegateJob(Guid id, ExecuteAction execAction, CanExecutePredicate canExecutePredicate, bool isThreadSafe, object syncRoot) : base(id, isThreadSafe, syncRoot) { if (execAction == null) { throw new ArgumentNullException("execAction"); } if (canExecutePredicate == null) { throw new ArgumentNullException("canExecutePredicate"); } this._EXECUTE_ACTION = execAction; this._CAN_EXECUTE_ACTION = delegate(DateTimeOffset time, ref bool canExecuteJob) { canExecuteJob = canExecutePredicate(time); }; }
/// <summary> /// Initializes a new instance of the <see cref="DelegateCommand{TParam}"/> class. /// </summary> /// <param name="executeAction">The logic for <see cref="DelegateCommand{TParam}.OnExecute(TParam)" />.</param> /// <param name="canExecutePredicate">The logic for <see cref="DelegateCommand{TParam}.CanExecute(TParam)" />.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="executeAction" /> is <see langword="null" />. /// </exception> public SimpleCommand(ExecuteHandler executeAction, CanExecutePredicate canExecutePredicate) : base(executeAction, canExecutePredicate) { }
public bool CanExecute(object parameter) { return(CanExecutePredicate == null || CanExecutePredicate.Invoke(parameter)); }
public bool CanExecute(object parameter) => !IsWorking && (CanExecutePredicate?.Invoke(parameter) ?? true);
/// <summary> /// Initializes a new instance of the <see cref="DelegateJob" /> class. /// </summary> /// <param name="id">The ID of the job.</param> /// <param name="execAction">An action for a <see cref="DelegateJob.OnExecute(IJobExecutionContext)" /> method.</param> /// <param name="canExecutePredicate">A predicate for a <see cref="DelegateJob.OnCanExecute(DateTimeOffset, ref bool)" /> method.</param> /// <param name="isThreadSafe">Job schould work thread safe or not.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="execAction" /> and/or <paramref name="canExecutePredicate" /> are <see langword="null" />. /// </exception> public DelegateJob(Guid id, ExecuteAction execAction, CanExecutePredicate canExecutePredicate, bool isThreadSafe) : this(id, execAction, canExecutePredicate, isThreadSafe, new object()) { }
/// <summary> /// Initializes a new instance of the <see cref="DelegateJob" /> class. /// </summary> /// <param name="id">The ID of the job.</param> /// <param name="execAction">An action for a <see cref="DelegateJob.OnExecute(IJobExecutionContext)" /> method.</param> /// <param name="canExecutePredicate">A predicate for a <see cref="DelegateJob.OnCanExecute(DateTimeOffset, ref bool)" /> method.</param> /// <param name="syncRoot">The object for thread safe operations.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="execAction" />, <paramref name="canExecutePredicate" /> and/or <paramref name="syncRoot" /> are <see langword="null" />. /// </exception> public DelegateJob(Guid id, ExecuteAction execAction, CanExecutePredicate canExecutePredicate, object syncRoot) : this(id, execAction, canExecutePredicate, false, syncRoot) { }
/// <summary> /// Initializes a new instance of the <see cref="DelegateJob" /> class. /// </summary> /// <param name="id">The ID of the job.</param> /// <param name="execAction">An action for a <see cref="DelegateJob.OnExecute(IJobExecutionContext)" /> method.</param> /// <param name="canExecutePredicate">A predicate for a <see cref="DelegateJob.OnCanExecute(DateTimeOffset, ref bool)" /> method.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="execAction" /> and/or <paramref name="canExecutePredicate" /> are <see langword="null" />. /// </exception> public DelegateJob(Guid id, ExecuteAction execAction, CanExecutePredicate canExecutePredicate) : this(id, execAction, canExecutePredicate, false) { }
public bool CanExecute(object parameter) { return(CanExecutePredicate?.Invoke((TPredicateObj)parameter) ?? true); }
protected override bool CanExecuteImplementation(object parameter) => parameter != null && (bool)CanExecutePredicate.DynamicInvoke((object[])parameter);
protected override bool CanExecuteImplementation(object parameter) => (bool)CanExecutePredicate.DynamicInvoke(parameter);