Идеальный подход - определить новый класс, унаследованный от ICommand, следующим образом:
public abstract class Command2<T1, T2> : ICommand {
public abstract T2 Execute2(T1 parameter);
}
public class DelegateCommand2<T1, T2> : Command2<T1, T2> {
public DelegateCommand2(Func<T1, T2> execute, Predicate<T1> canExecute) {
_execute = execute;
_canExecute = canExecute;
}
public override T2 Execute2(T1 parameter) {
if (CanExecute(parameter) == false)
return default(T2);
else
return _execute((T1)parameter);
}
}
Обратите внимание, что Execute2 возвращает значение как обычная функция.
Вот как это использовать.
private readonly ICommand _commandExample = new DelegateCommand2<int, Point3D>(
commandExample_Executed,
commandExample_CanExecute
);
public Command2<int, Point_3D> CommandExample {
get {
return (Command2<int, Point_3D>) _commandExample;
}
}
private static Point3D commandExample_Executed(int index) {
return Fun1(index); //Fun1 returns a Point_3D
}
private static bool commandExample_CanExecute(int index) {
return true;
}
Вызовы Execute2 вместо Execute вернут значение.