Delegate在.net核心中不包含CreateDelegate的定义

时间:2017-05-09 09:16:31

标签: c# reflection .net-core

我正在尝试使用代理在dotNet核心Web应用程序中进行反射。以下是代码示例。

Action action = (Action) Delegate.CreateDelegate(typeof(Action), method)

编译器出现以下错误:

'Delegate' does not contain a definition for 'CreateDelegate'   ConsoleApp2..NETCoreApp,Version=v1.0'

是否有任何解决方法可以在.net Core中创建委托?

1 个答案:

答案 0 :(得分:6)

请改用MethodInfo.CreateDelegate

MethodInfo methodInfo = target.GetType().GetMethod(nameof(FooMethod));

Action action = (Action) methodInfo.CreateDelegate(typeof(Action), target);
预计

Delegate.CreateDelegate将在.NET Core 2.0中返回:.NET API Catalog

相关问题