Created
February 3, 2021 17:06
-
-
Save guntidheerajkumar/a096d27f08aef49ccbc6c199e61ed96c to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Threading.Tasks; | |
using System.Windows.Input; | |
using Microsoft.AppCenter.Analytics; | |
namespace DotnetMobileCommands | |
{ | |
public class MobileCommand<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 MobileCommand(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 MobileCommand : ICommand | |
{ | |
private Action _action; | |
private Action<object> _newAction; | |
private string _activityName; | |
private bool _canExecute; | |
public event EventHandler CanExecuteChanged; | |
public MobileCommand(string activityName, Action action) | |
{ | |
_activityName = activityName; | |
_action = action; | |
_canExecute = true; | |
} | |
public SmartTeamCommand(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