Delegate.CreateDelegate 方法

定義

建立指定類型的委派。

多載

CreateDelegate(Type, Object, String, Boolean, Boolean)

建立指定之類型的委派,其表示要在指定的類別執行個體上叫用的指定執行個體方法,且會指定區分大小寫的方式以及在繫結失敗時要發生的行為。

CreateDelegate(Type, Type, String, Boolean)

建立指定之類型的委派,其表示指定之類別的指定靜態方法,且指定區分大小寫的方式。

CreateDelegate(Type, Object, String, Boolean)

建立指定類型的委派,這個委派表示要在指定的類別執行個體上,使用指定的大小寫區分來叫用的指定執行個體方法。

CreateDelegate(Type, Object, MethodInfo, Boolean)

建立指定之類型的委派,其表示指定之靜態或執行個體方法,並有指定第一個引數以及繫結失敗時所發生的行為。

CreateDelegate(Type, Type, String, Boolean, Boolean)

建立指定之類型的委派,其表示指定之類別的指定靜態方法,且會指定區分大小寫的方式以及在繫結失敗時要發生的行為。

CreateDelegate(Type, MethodInfo, Boolean)

建立指定之類型的委派,用來表示指定之靜態方法,並包含在繫結失敗時發生的指定之行為。

CreateDelegate(Type, Object, String)

建立指定類型的委派,這個委派表示要在指定的類別執行個體上叫用的指定執行個體方法。

CreateDelegate(Type, Object, MethodInfo)

建立指定之類型的委派,其表示指定之靜態或執行個體方法,並有指定第一個引數。

CreateDelegate(Type, MethodInfo)

建立指定型別的委派,以表示指定的方法。

CreateDelegate(Type, Type, String)

建立指定類型的委派,這個委派表示指定類別的指定靜態方法。

CreateDelegate(Type, Object, String, Boolean, Boolean)

Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs

建立指定之類型的委派,其表示要在指定的類別執行個體上叫用的指定執行個體方法,且會指定區分大小寫的方式以及在繫結失敗時要發生的行為。

public:
 static Delegate ^ CreateDelegate(Type ^ type, System::Object ^ target, System::String ^ method, bool ignoreCase, bool throwOnBindFailure);
public static Delegate? CreateDelegate (Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure);
public static Delegate CreateDelegate (Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure);
static member CreateDelegate : Type * obj * string * bool * bool -> Delegate
Public Shared Function CreateDelegate (type As Type, target As Object, method As String, ignoreCase As Boolean, throwOnBindFailure As Boolean) As Delegate

參數

type
Type

要建立之委派的 Type

target
Object

叫用 method 的類別執行個體。

method
String

委派要表示的執行個體方法名稱。

ignoreCase
Boolean

布林值 (Boolean),指出是否在比較方法名稱時忽略大小寫。

throwOnBindFailure
Boolean

method 表示如果無法繫結 true 時,則擲回例外狀況;否則為 false

傳回

指定類型的委派,表示要在指定的類別執行個體上叫用的指定執行個體方法。

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不會繼承 MulticastDelegate

-或-

type 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或-

method 不是執行個體方法。

-或-

無法繫結 method,例如因為找不到該方法,以及 throwOnBindFailuretrue

找不到 typeInvoke 方法。

呼叫端沒有存取 method 所需的權限。

備註

這個方法只會建立實例方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。

另請參閱

適用於

CreateDelegate(Type, Type, String, Boolean)

Source:
Delegate.cs
Source:
Delegate.cs
Source:
Delegate.cs

建立指定之類型的委派,其表示指定之類別的指定靜態方法,且指定區分大小寫的方式。

public:
 static Delegate ^ CreateDelegate(Type ^ type, Type ^ target, System::String ^ method, bool ignoreCase);
public static Delegate CreateDelegate (Type type, Type target, string method, bool ignoreCase);
static member CreateDelegate : Type * Type * string * bool -> Delegate
Public Shared Function CreateDelegate (type As Type, target As Type, method As String, ignoreCase As Boolean) As Delegate

參數

type
Type

要建立之委派的 Type

target
Type

Type,代表可實作 method 的類別。

method
String

委派要表示的靜態方法名稱。

ignoreCase
Boolean

布林值 (Boolean),指出是否在比較方法名稱時忽略大小寫。

傳回

指定類型的委派,表示指定類別的指定靜態方法。

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不會繼承 MulticastDelegate

-或-

type 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或-

target 不是 RuntimeType

-或-

target 是開放式泛型型別。 亦即,其 ContainsGenericParameters 屬性為 true

-或-

method 不是 static 方法 (Visual Basic 中的 Shared 方法)。

-或-

例如,因為找不到 method,所以無法將其繫結。

找不到 typeInvoke 方法。

呼叫端沒有存取 method 所需的權限。

備註

這個方法只會建立靜態方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。

這個方法多載相當於呼叫 CreateDelegate(Type, Type, String, Boolean, Boolean) 方法多載,並 true 針對 throwOnBindFailure指定 。

另請參閱

適用於

CreateDelegate(Type, Object, String, Boolean)

Source:
Delegate.cs
Source:
Delegate.cs
Source:
Delegate.cs

建立指定類型的委派,這個委派表示要在指定的類別執行個體上,使用指定的大小寫區分來叫用的指定執行個體方法。

public:
 static Delegate ^ CreateDelegate(Type ^ type, System::Object ^ target, System::String ^ method, bool ignoreCase);
public static Delegate CreateDelegate (Type type, object target, string method, bool ignoreCase);
static member CreateDelegate : Type * obj * string * bool -> Delegate
Public Shared Function CreateDelegate (type As Type, target As Object, method As String, ignoreCase As Boolean) As Delegate

參數

type
Type

要建立之委派的 Type

target
Object

叫用 method 的類別執行個體。

method
String

委派要表示的執行個體方法名稱。

ignoreCase
Boolean

布林值 (Boolean),指出是否在比較方法名稱時忽略大小寫。

傳回

指定類型的委派,表示要在指定的類別執行個體上叫用的指定執行個體方法。

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不會繼承 MulticastDelegate

-或-

type 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或-

method 不是執行個體方法。

-或-

例如,因為找不到 method,所以無法將其繫結。

找不到 typeInvoke 方法。

呼叫端沒有存取 method 所需的權限。

備註

這個方法只會建立實例方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。

這個方法多載相當於呼叫 CreateDelegate(Type, Object, String, Boolean, Boolean) 方法多載,並 true 針對 throwOnBindFailure指定 。

另請參閱

適用於

CreateDelegate(Type, Object, MethodInfo, Boolean)

Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs

建立指定之類型的委派,其表示指定之靜態或執行個體方法,並有指定第一個引數以及繫結失敗時所發生的行為。

public:
 static Delegate ^ CreateDelegate(Type ^ type, System::Object ^ firstArgument, System::Reflection::MethodInfo ^ method, bool throwOnBindFailure);
public static Delegate? CreateDelegate (Type type, object? firstArgument, System.Reflection.MethodInfo method, bool throwOnBindFailure);
public static Delegate CreateDelegate (Type type, object firstArgument, System.Reflection.MethodInfo method, bool throwOnBindFailure);
static member CreateDelegate : Type * obj * System.Reflection.MethodInfo * bool -> Delegate
Public Shared Function CreateDelegate (type As Type, firstArgument As Object, method As MethodInfo, throwOnBindFailure As Boolean) As Delegate

參數

type
Type

Type,表示要建立的委派之類型。

firstArgument
Object

Object,委派所表示的方法之第一個引數。 對於執行個體方法而言,它必須與執行個體類型相容。

method
MethodInfo

MethodInfo,描述委派所要表示的靜態或執行個體方法。

throwOnBindFailure
Boolean

method 表示如果無法繫結 true 時,則擲回例外狀況;否則為 false

傳回

指定之類型的委派,表示指定之靜態或執行個體方法;如果 throwOnBindFailurefalse,且委派無法繫結至 method,則為 null

例外狀況

typenull

-或-

methodnull

type 不會繼承 MulticastDelegate

-或-

type 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或-

無法繫結 method,而且 throwOnBindFailuretrue

-或-

method 不是 RuntimeMethodInfo。 請參閱 Runtime Types in Reflection

找不到 typeInvoke 方法。

呼叫端沒有存取 method 所需的權限。

備註

這個方法多載和 CreateDelegate(Type, Object, MethodInfo) 方法多載,一律會在無法系結時擲回,提供最有彈性的方式來建立委派。 您可以使用它們來建立靜態或實例方法的委派,而不需要第一個自變數。

注意

如果您未提供第一個自變數,請使用 CreateDelegate(Type, MethodInfo, Boolean) 方法多載來提升效能。

如需詳細資訊和範例,請參閱 System.Delegate.CreateDelegate 的補充 API 備註

另請參閱

適用於

CreateDelegate(Type, Type, String, Boolean, Boolean)

Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs

建立指定之類型的委派,其表示指定之類別的指定靜態方法,且會指定區分大小寫的方式以及在繫結失敗時要發生的行為。

public:
 static Delegate ^ CreateDelegate(Type ^ type, Type ^ target, System::String ^ method, bool ignoreCase, bool throwOnBindFailure);
public static Delegate? CreateDelegate (Type type, Type target, string method, bool ignoreCase, bool throwOnBindFailure);
public static Delegate CreateDelegate (Type type, Type target, string method, bool ignoreCase, bool throwOnBindFailure);
static member CreateDelegate : Type * Type * string * bool * bool -> Delegate
Public Shared Function CreateDelegate (type As Type, target As Type, method As String, ignoreCase As Boolean, throwOnBindFailure As Boolean) As Delegate

參數

type
Type

要建立之委派的 Type

target
Type

Type,代表可實作 method 的類別。

method
String

委派要表示的靜態方法名稱。

ignoreCase
Boolean

布林值 (Boolean),指出是否在比較方法名稱時忽略大小寫。

throwOnBindFailure
Boolean

method 表示如果無法繫結 true 時,則擲回例外狀況;否則為 false

傳回

指定類型的委派,表示指定類別的指定靜態方法。

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不會繼承 MulticastDelegate

-或-

type 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或-

target 不是 RuntimeType

-或-

target 是開放式泛型型別。 亦即,其 ContainsGenericParameters 屬性為 true

-或-

method 不是 static 方法 (Visual Basic 中的 Shared 方法)。

-或-

無法繫結 method,例如因為找不到該方法,以及 throwOnBindFailuretrue

找不到 typeInvoke 方法。

呼叫端沒有存取 method 所需的權限。

備註

這個方法只會建立靜態方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。

另請參閱

適用於

CreateDelegate(Type, MethodInfo, Boolean)

Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs

建立指定之類型的委派,用來表示指定之靜態方法,並包含在繫結失敗時發生的指定之行為。

public:
 static Delegate ^ CreateDelegate(Type ^ type, System::Reflection::MethodInfo ^ method, bool throwOnBindFailure);
public static Delegate? CreateDelegate (Type type, System.Reflection.MethodInfo method, bool throwOnBindFailure);
public static Delegate CreateDelegate (Type type, System.Reflection.MethodInfo method, bool throwOnBindFailure);
static member CreateDelegate : Type * System.Reflection.MethodInfo * bool -> Delegate
Public Shared Function CreateDelegate (type As Type, method As MethodInfo, throwOnBindFailure As Boolean) As Delegate

參數

type
Type

要建立之委派的 Type

method
MethodInfo

MethodInfo,描述委派所要表示的靜態或執行個體方法。

throwOnBindFailure
Boolean

method 表示如果無法繫結 true 時,則擲回例外狀況;否則為 false

傳回

指定類型的委派,用來表示指定的靜態方法。

例外狀況

typenull

-或-

methodnull

type 不會繼承 MulticastDelegate

-或-

type 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或-

無法繫結 method,而且 throwOnBindFailuretrue

-或-

method 不是 RuntimeMethodInfo。 請參閱 Runtime Types in Reflection

找不到 typeInvoke 方法。

呼叫端沒有存取 method 所需的權限。

備註

這個方法多載可以建立開放式靜態方法委派和開啟的實例方法委派,也就是公開實例方法之隱藏第一個自變數的委派。 如需詳細說明,請參閱更一般 CreateDelegate(Type, Object, MethodInfo, Boolean) 的方法多載,這可讓您建立實例或靜態方法之開啟或關閉委派的所有組合。

注意

當委派未在其第一個自變數上關閉時,應該使用這個方法多載,因為在此情況下會比較快。

如需範例,請參閱 System.Delegate.CreateDelegate 的補充 API 備註

另請參閱

適用於

CreateDelegate(Type, Object, String)

Source:
Delegate.cs
Source:
Delegate.cs
Source:
Delegate.cs

建立指定類型的委派,這個委派表示要在指定的類別執行個體上叫用的指定執行個體方法。

public:
 static Delegate ^ CreateDelegate(Type ^ type, System::Object ^ target, System::String ^ method);
public static Delegate CreateDelegate (Type type, object target, string method);
static member CreateDelegate : Type * obj * string -> Delegate
Public Shared Function CreateDelegate (type As Type, target As Object, method As String) As Delegate

參數

type
Type

要建立之委派的 Type

target
Object

叫用 method 的類別執行個體。

method
String

委派要表示的執行個體方法名稱。

傳回

指定類型的委派,表示要在指定的類別執行個體上叫用的指定執行個體方法。

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不會繼承 MulticastDelegate

-或-

type 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或-

method 不是執行個體方法。

-或-

例如,因為找不到 method,所以無法將其繫結。

找不到 typeInvoke 方法。

呼叫端沒有存取 method 所需的權限。

備註

這個方法只會建立實例方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。

這個方法多載相當於呼叫 CreateDelegate(Type, Object, String, Boolean, Boolean) 方法多載,並falseignoreCase針對 throwOnBindFailure指定 和 true

另請參閱

適用於

CreateDelegate(Type, Object, MethodInfo)

Source:
Delegate.cs
Source:
Delegate.cs
Source:
Delegate.cs

建立指定之類型的委派,其表示指定之靜態或執行個體方法,並有指定第一個引數。

public:
 static Delegate ^ CreateDelegate(Type ^ type, System::Object ^ firstArgument, System::Reflection::MethodInfo ^ method);
public static Delegate CreateDelegate (Type type, object? firstArgument, System.Reflection.MethodInfo method);
public static Delegate CreateDelegate (Type type, object firstArgument, System.Reflection.MethodInfo method);
static member CreateDelegate : Type * obj * System.Reflection.MethodInfo -> Delegate
Public Shared Function CreateDelegate (type As Type, firstArgument As Object, method As MethodInfo) As Delegate

參數

type
Type

要建立之委派的 Type

firstArgument
Object

此委派要繫結的物件,或是 null,表示將 method 視為 static (Visual Basic 中則為 Shared)。

method
MethodInfo

MethodInfo,描述委派所要表示的靜態或執行個體方法。

傳回

指定之類型的委派,其表示指定的靜態或執行個體方法。

例外狀況

typenull

-或-

methodnull

type 不會繼承 MulticastDelegate

-或-

type 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或-

無法繫結 method

-或-

method 不是 RuntimeMethodInfo。 請參閱 Runtime Types in Reflection

找不到 typeInvoke 方法。

呼叫端沒有存取 method 所需的權限。

備註

呼叫這個方法多載相當於呼叫 CreateDelegate(Type, Object, MethodInfo, Boolean) 方法多載,並針對 throwOnBindFailure指定 true 。 這兩個多載提供最有彈性的方式來建立委派。 您可以使用它們來建立靜態或實例方法的委派,並選擇性地指定第一個自變數。

注意

如果您沒有提供第一個自變數,請使用 CreateDelegate(Type, MethodInfo) 方法多載以提升效能。

如需此 API 的詳細資訊,請參閱 System.Delegate.CreateDelegate 的補充 API 備註

另請參閱

適用於

CreateDelegate(Type, MethodInfo)

Source:
Delegate.cs
Source:
Delegate.cs
Source:
Delegate.cs

建立指定型別的委派,以表示指定的方法。

public:
 static Delegate ^ CreateDelegate(Type ^ type, System::Reflection::MethodInfo ^ method);
public static Delegate CreateDelegate (Type type, System.Reflection.MethodInfo method);
static member CreateDelegate : Type * System.Reflection.MethodInfo -> Delegate
Public Shared Function CreateDelegate (type As Type, method As MethodInfo) As Delegate

參數

type
Type

要建立之委派的 Type

method
MethodInfo

MethodInfo,描述委派所要表示的靜態或執行個體方法。

傳回

指定型別的委派,表示指定的方法。

例外狀況

typenull

-或-

methodnull

type 不會繼承 MulticastDelegate

-或-

type 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或-

無法繫結 method

-或-

method 不是 RuntimeMethodInfo。 請參閱 Runtime Types in Reflection

找不到 typeInvoke 方法。

呼叫端沒有存取 method 所需的權限。

備註

此多載可以建立靜態方法的委派和開啟的實例方法委派;也就是說,明確提供實例方法之隱藏第一個自變數的委派。 如需詳細說明,請參閱更一般 CreateDelegate(Type, Object, MethodInfo) 的方法多載,這可讓您建立實例或靜態方法的開啟或關閉委派的所有組合,並選擇性地指定第一個自變數。

注意

當委派未在其第一個自變數上關閉時,應該使用這個方法多載,因為在此情況下會比較快。

如需此 API 的詳細資訊,請參閱 System.Delegate.CreateDelegate 的補充 API 備註

另請參閱

適用於

CreateDelegate(Type, Type, String)

Source:
Delegate.cs
Source:
Delegate.cs
Source:
Delegate.cs

建立指定類型的委派,這個委派表示指定類別的指定靜態方法。

public:
 static Delegate ^ CreateDelegate(Type ^ type, Type ^ target, System::String ^ method);
public static Delegate CreateDelegate (Type type, Type target, string method);
static member CreateDelegate : Type * Type * string -> Delegate
Public Shared Function CreateDelegate (type As Type, target As Type, method As String) As Delegate

參數

type
Type

要建立之委派的 Type

target
Type

Type,代表可實作 method 的類別。

method
String

委派要表示的靜態方法名稱。

傳回

指定類型的委派,表示指定類別的指定靜態方法。

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不會繼承 MulticastDelegate

-或-

type 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或-

target 不是 RuntimeType

-或-

target 是開放式泛型型別。 亦即,其 ContainsGenericParameters 屬性為 true

-或-

method 不是 static 方法 (Visual Basic 中的 Shared 方法)。

-或-

無法繫結 method,例如因為找不到該方法,以及 throwOnBindFailuretrue

找不到 typeInvoke 方法。

呼叫端沒有存取 method 所需的權限。

備註

這個方法只會建立靜態方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。

這個方法多載相當於呼叫 CreateDelegate(Type, Type, String, Boolean, Boolean) 方法多載,並falseignoreCase針對 throwOnBindFailure指定 和 true

另請參閱

適用於