Created
January 23, 2021 01:21
-
-
Save CheetahChrome/9cf3f3f3004f697ab7460a9f3203bc97 to your computer and use it in GitHub Desktop.
ICommand
This file contains 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 OperationCommand : ICommand | |
{ | |
#region Variables | |
private Func<object, bool> CanExecuteHandler { get; set; } | |
private Action<object> ExecuteActionHandler { get; set; } | |
public bool InSeparateThread { get; set; } | |
#endregion | |
#region Properties | |
#endregion | |
#region Construction/Initialization | |
public OperationCommand(Action<object> executeAction, bool inSeparateThread = false) | |
{ | |
InSeparateThread = inSeparateThread; | |
ExecuteActionHandler = executeAction ?? throw new ArgumentNullException(nameof(executeAction)); | |
} | |
public OperationCommand(Action<object> executeAction, Func<object, bool> canExecute) : this(executeAction) | |
{ | |
CanExecuteHandler = canExecute; | |
} | |
// Here to adhere to ICommand, change to below if needed | |
//public event EventHandler CanExecuteChanged; | |
event EventHandler ICommand.CanExecuteChanged | |
{ | |
add {} | |
remove {} | |
} | |
#endregion | |
#region Methods | |
public bool CanExecute(object parameter) => CanExecuteHandler?.Invoke(parameter) ?? true; | |
// public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, new EventArgs()); | |
public void Execute(object parameter) | |
{ | |
ExecuteActionHandler?.Invoke(parameter); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment