Я хочу получить делегата действия от объекта MethodInfo. Действительно ли это возможно?
Используйте Delegate.CreateDelegate :
// Static method
Action action = (Action) Delegate.CreateDelegate(typeof(Action), method);
// Instance method (on "target")
Action action = (Action) Delegate.CreateDelegate(typeof(Action), target, method);
Для Action
и т. Д. Просто укажите везде соответствующий тип делегата.
В .NET Core Delegate.CreateDelegate
не существует, но MethodInfo.CreateDelegate
существует:
// Static method
Action action = (Action) method.CreateDelegate(typeof(Action));
// Instance method (on "target")
Action action = (Action) method.CreateDelegate(typeof(Action), target);