I have a generic Command of type ICommand
:
class SimpleCommand<T> : ICommand
{
public SimpleCommand(Action<T> execute, Predicate<T> canExecute = null)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
/*
All the other stuff...
*/
}
Used like this:
ICommand command = new SimpleCommand<string>(MyMethod);
private void MyMethod(string arg) { ... }
When using i would like the compiler to automaticly pick up the T from the Action passed, so i can just write like tihs:
ICommand command = new SimpleCommand(MyMethod);
However if i write like so, i get an compiler error. Is it possible to make the compiler pick up the T class from the Method parameter type ?