簡體   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