Hi,
for CanExecute you must implement the same code:
public class Command<T> : ICommand
{
private readonly Action<T> _execute;
private readonly Predicate<T> _canExecute;
public Command(Action<T> _) { _execute = _; _canExecute = null; }
public Command(Action<T> execute, Predicate<T> _) { this._canExecute = _; this._execute = execute; }
public void Execute(object _)
{
if (_ is IEnumerable)
{
var para = (IEnumerable)_;
var type = typeof(T);
var list = Activator.CreateInstance(type);
foreach (var item in para) type.GetMethod("Add").Invoke(list, new[] { item });
this._execute((T)list);
}
else this._execute((T)_);
}
public bool CanExecute(object _)
{
if (this._canExecute == null) return true;
if (_ is IEnumerable)
{
var para = (IEnumerable)_;
var type = typeof(T);
var list = Activator.CreateInstance(type);
foreach (var item in para) type.GetMethod("Add").Invoke(list, new[] { item });
return this._canExecute((T)list);
}
return this._canExecute((T)_);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
}