Created
October 14, 2019 16:08
-
-
Save Plus1XP/4e687b08db75a9f05c16569f5abdbfbf to your computer and use it in GitHub Desktop.
RelayCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RelayCommandAsync<T> : ICommand | |
{ | |
private readonly Func<T, Task> executedMethod; | |
private readonly Func<T, bool> canExecuteMethod; | |
public event EventHandler CanExecuteChanged; | |
public RelayCommandAsync(Func<T, Task> execute) : this(execute, null) { } | |
public RelayCommandAsync(Func<T, Task> execute, Func<T, bool> canExecute) | |
{ | |
this.executedMethod = execute ?? throw new ArgumentNullException("execute"); | |
this.canExecuteMethod = canExecute; | |
} | |
public bool CanExecute(object parameter) => this.canExecuteMethod == null || this.canExecuteMethod((T)parameter); | |
public async void Execute(object parameter) => await this.executedMethod((T)parameter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment