Skip to content

Instantly share code, notes, and snippets.

@guntidheerajkumar
Created July 8, 2020 17:40
Show Gist options
  • Save guntidheerajkumar/fc648ff3e24bf7cc5c6f22e0cca9a26e to your computer and use it in GitHub Desktop.
Save guntidheerajkumar/fc648ff3e24bf7cc5c6f22e0cca9a26e to your computer and use it in GitHub Desktop.
namespace Mobile.Commands
{
public class CustomCommand<T> : ICommand
{
private Action _action;
private Action<object> _newAction;
private string _activityName;
private bool _canExecute;
private readonly Func<T, Task> _executeTask;
public event EventHandler CanExecuteChanged;
public CustomCommand(string activityName, Func<T, Task> executeTask)
{
_executeTask = executeTask;
_activityName = activityName;
_canExecute = true;
}
public bool CanExecute(object parameter)
{
return _canExecute;
}
public void Execute(object parameter)
{
Analytics.TrackEvent($"Perforced action : {_activityName}");
_executeTask.Invoke((T)parameter);
}
}
public class CustomCommand : ICommand
{
private Action _action;
private Action<object> _newAction;
private string _activityName;
private bool _canExecute;
public event EventHandler CanExecuteChanged;
public CustomCommand(string activityName, Action action)
{
_activityName = activityName;
_action = action;
_canExecute = true;
}
public CustomCommand(string activityName, Action<object> action)
{
_activityName = activityName;
_newAction = action;
_canExecute = true;
}
public bool CanExecute(object parameter)
{
return _canExecute;
}
public void Execute(object parameter)
{
Analytics.TrackEvent($"Perforced action : {_activityName}");
_action();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment