简体   繁体   English

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

[英]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.

相关问题 委托不包含“ CreateDelegate”的定义 - Delegate does not contain a definition for 'CreateDelegate' 网络核心:“ HttpContext”不包含“当前”的定义 - Net Core: 'HttpContext' does not contain a definition for 'Current'` 'string' 不包含 .Net Core 中 'AsInt' 的定义 - 'string' does not contain a definition for 'AsInt' in .Net Core http请求在.net core 2.1中不包含createresponse的定义 - http request does not contain a definition for createresponse in .net core 2.1 .NET Core:Array类不包含ConvertAll的定义 - .NET Core: Array class does not contain definition for ConvertAll .net 核心 3.1:&#39;IAsyncEnumerable<string> &#39; 不包含 &#39;GetAwaiter&#39; 的定义 - .net core 3.1: 'IAsyncEnumerable<string>' does not contain a definition for 'GetAwaiter' .NET Core 3.1 - HostingEnvironment 不包含 MapPath 的定义 - .NET Core 3.1 - HostingEnvironment does not contain a definition for MapPath ASP.NET Core:IConfigurationBuilder 不包含 AddAzureKeyVault 的定义 - ASP.NET Core: IConfigurationBuilder Does Not Contain Definition For AddAzureKeyVault .net core 3.1 Blazor WebAssembly:不包含“LoginMode”的定义 - .net core 3.1 Blazor WebAssembly: does not contain a definition for "LoginMode" .NET Core Xunit - IActionResult&#39; 不包含 &#39;StatusCode&#39; 的定义 - .NET Core Xunit - IActionResult' does not contain a definition for 'StatusCode'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM