[英]Delegate does not contain a definition for CreateDelegate in .net core
I'm trying to use delegates for reflection in dotNet core web application. 我正在尝试使用代理在dotNet核心Web应用程序中进行反射。 Below is the sample of the code.
以下是代码示例。
Action action = (Action) Delegate.CreateDelegate(typeof(Action), method)
Compiler gives the following error: 编译器给出以下错误:
'Delegate' does not contain a definition for 'CreateDelegate' ConsoleApp2..NETCoreApp,Version=v1.0'
Is there any work around for creating delegates in .net Core? 是否有任何解决方法在.net Core中创建代理?
Use MethodInfo.CreateDelegate
instead. 请改用
MethodInfo.CreateDelegate
。
MethodInfo methodInfo = target.GetType().GetMethod(nameof(FooMethod));
Action action = (Action) methodInfo.CreateDelegate(typeof(Action), target);
Delegate.CreateDelegate
is expected to return in .NET Core 2.0: .NET API Catalog Delegate.CreateDelegate
应该在.NET Core 2.0: .NET API目录中返回
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.