2017-05-09 1 views
5

dotNetコアWebアプリケーションでリフレクションに代理人を使用しようとしています。以下はコードのサンプルです。Delegateに.netコアのCreateDelegateの定義が含まれていない

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

コンパイラは次のエラーを与える:

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

は、.NETのコアでデリゲートを作成するための周りのすべての作業はありますか?

答えて

4

代わりにMethodInfo.CreateDelegateを使用してください。

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

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

Delegate.CreateDelegateは、.NETコア2.0に戻すことが期待される:.NET API Catalog

関連する問題