| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="RelayCommandFactory.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | using System.Windows.Input; |
| | | 10 | | using MyNet.UI.Threading; |
| | | 11 | | |
| | | 12 | | namespace MyNet.UI.Commands; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// A factory for creating RelayCommand and AsyncRelayCommand instances, optionally using a provided scheduler for comma |
| | | 16 | | /// </summary> |
| | | 17 | | /// <param name="schedulerProvider">The scheduler provider for UI thread scheduling.</param> |
| | | 18 | | public class RelayCommandFactory(ISchedulerProvider? schedulerProvider = null) : ICommandFactory |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets a default instance of the <see cref="RelayCommandFactory"/> that uses the default scheduler provider. |
| | | 22 | | /// </summary> |
| | 3 | 23 | | public static readonly RelayCommandFactory Default = new(); |
| | | 24 | | |
| | | 25 | | // <inheritdoc /> |
| | 183 | 26 | | public ICommand Create(Action execute) => new RelayCommand(execute, schedulerProvider: schedulerProvider); |
| | | 27 | | |
| | | 28 | | // <inheritdoc /> |
| | 594 | 29 | | public ICommand Create(Action execute, Func<bool> canExecute) => new RelayCommand(execute, canExecute, schedulerProv |
| | | 30 | | |
| | | 31 | | // <inheritdoc /> |
| | 135 | 32 | | public ICommand Create<T>(Action<T?> execute) => new RelayCommand<T>(execute, schedulerProvider: schedulerProvider); |
| | | 33 | | |
| | | 34 | | // <inheritdoc /> |
| | 132 | 35 | | public ICommand Create<T>(Action<T?> execute, Func<T?, bool> canExecute) => new RelayCommand<T>(execute, canExecute, |
| | | 36 | | |
| | | 37 | | // <inheritdoc /> |
| | 27 | 38 | | public ICommand Create(Func<Task> execute) => new AsyncRelayCommand(execute, schedulerProvider: schedulerProvider); |
| | | 39 | | |
| | | 40 | | // <inheritdoc /> |
| | 324 | 41 | | public ICommand Create(Func<Task> execute, Func<bool> canExecute) => new AsyncRelayCommand(execute, canExecute, sche |
| | | 42 | | |
| | | 43 | | // <inheritdoc /> |
| | 0 | 44 | | public ICommand Create<T>(Func<T?, Task> execute) => new AsyncRelayCommand<T>(execute, schedulerProvider: schedulerP |
| | | 45 | | |
| | | 46 | | // <inheritdoc /> |
| | 42 | 47 | | public ICommand Create<T>(Func<T?, Task> execute, Func<T?, bool> canExecute) => new AsyncRelayCommand<T>(execute, ca |
| | | 48 | | } |
| | | 49 | | |