假设我有这个通用方法
void ActivateView<T>(ViewCommand command) where T : IPresenter
{
//code
}
我有一个动作:
Action<ViewCommand> action = this.ActivateView<DiagnosticPresenter>;
现在给出action
,我怎么知道泛型方法的类型参数ActivateView
?在这种情况下,它应该是DiagnosticPresenter
。所以我期待一个Type
等于的实例typeof(DiagnosticPresenter)
:
Type type = Magic(action); //what should Magic do?
if ( type == typeof(DiagnosticPresenter))
{
//I want to do something here!
}
那可能吗?我应该如何实施Magic()
?