Suppose I’ve this generic method
void ActivateView<T>(ViewCommand command) where T : IPresenter
{
//code
}
And I’ve an action as:
Action<ViewCommand> action = this.ActivateView<DiagnosticPresenter>;
Now given action, how can I know the type arument to the generic method ActivateView? In this case, it should be DiagnosticPresenter. So I’m expecting an instance of Type equal to typeof(DiagnosticPresenter) as:
Type type = Magic(action); //what should Magic do?
if ( type == typeof(DiagnosticPresenter))
{
//I want to do something here!
}
Is that possible? How should I implementMagic()?
This appears to work for me: