繁体   English   中英

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

[英]Delegate does not contain a definition for CreateDelegate in .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中创建代理?

请改用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目录中返回

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM