次の方法で共有


Delegate.CreateDelegate メソッド (Type, Object, String)

指定したクラス インスタンスに対して呼び出す指定したインスタンス メソッドを表す、指定した型のデリゲートを作成します。

Overloads Public Shared Function CreateDelegate( _
   ByVal type As Type, _   ByVal target As Object, _   ByVal method As String _) As Delegate
[C#]
public static Delegate CreateDelegate(Typetype,objecttarget,stringmethod);
[C++]
public: static Delegate* CreateDelegate(Type* type,Object* target,String* method);
[JScript]
public static function CreateDelegate(
   type : Type,target : Object,method : String) : Delegate;

パラメータ

  • type
    作成するデリゲートの Type
  • target
    method を呼び出す対象のクラス インスタンス。
  • method
    デリゲートによって表されるインスタンス メソッドの名前。

戻り値

指定したクラス インスタンスに対して呼び出す指定したインスタンス メソッドを表す、指定した型のデリゲート。

例外

例外の種類 条件
ArgumentNullException type が null 参照 (Visual Basic では Nothing) です。

または

target が null 参照 (Nothing) です。

または

method が null 参照 (Nothing) です。

ArgumentException type が Delegate または MulticastDelegate のどちらからも継承されていません。

または

method がインスタンス メソッドではありません。

InvalidProgramException type の Invoke メソッドが見つかりません。
MemberAccessException 呼び出し元には、(たとえば、メソッドがプライベート メソッドの場合に) デリゲートが表すメソッドへのアクセス権がありません。
MethodAccessException method が現在のアセンブリ外にあり、呼び出し元には、 method を格納しているアセンブリへの ReflectionPermission がありません。

解説

このメソッドは、インスタンス メソッドのデリゲートだけを作成します。インスタンス メソッドとは、クラスのインスタンスに関連付けられるメソッドです。静的メソッドとは、クラス自体に関連付けられるメソッドです。

クラスを表す Type を取得するには、そのクラスの (名前空間を含む) 完全限定名で Type.GetType メソッドを使用します。たとえば、"System.Threading.ThreadStart" を Type.GetType に渡すと、 ThreadStart クラスの Type が返されます。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard

.NET Framework セキュリティ:

参照

Delegate クラス | Delegate メンバ | System 名前空間 | Delegate.CreateDelegate オーバーロードの一覧 | Type | MulticastDelegate | ReflectionPermission | Object