Delegate.CreateDelegate 方法

定義

建立指定型別的委派。

多載

名稱 Description
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)

來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs

建立指定型別的委派,這個委派表示指定類別實例上要叫用的指定實例方法,並具有指定的區分大小寫,以及無法系結的指定行為。

public:
 static Delegate ^ CreateDelegate(Type ^ type, System::Object ^ target, System::String ^ method, bool ignoreCase, bool throwOnBindFailure);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")]
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);
public static Delegate? CreateDelegate(Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")>]
static member CreateDelegate : Type * obj * string * bool * bool -> Delegate
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

布爾值,指出比較方法名稱時是否忽略大小寫。

throwOnBindFailure
Boolean

true若無法method束縛,則拋出例外;否則,。 false

傳回

指定型別的委派,表示在指定的類別實例上叫用的指定實例方法。

屬性

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不繼承 MulticastDelegate

-或-

type 不是 RuntimeType

-或-

method 不是實例方法。

-或-

method 無法被束縛,例如因為找不到,且 throwOnBindFailuretrue

Invoke未找到 的方法type

呼叫者沒有存取 method的權限。

備註

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

另請參閱

適用於

CreateDelegate(Type, Type, String, Boolean)

來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
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);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")]
public static Delegate CreateDelegate(Type type, Type target, string method, bool ignoreCase);
static member CreateDelegate : Type * Type * string * bool -> Delegate
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")>]
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

表示 Typemethod作 的類別。

method
String

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

ignoreCase
Boolean

布爾值,指出比較方法名稱時是否忽略大小寫。

傳回

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

屬性

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不繼承 MulticastDelegate

-或-

type 不是 RuntimeType

-或-

target 不是 RuntimeType

-或-

target 是一種開放式通用型。 也就是說,其 ContainsGenericParameters 性質為 true

-或-

method 並非 static 方法(Visual Basic 中的 Shared 方法)。

-或-

method 無法綁定,例如因為找不到。

Invoke未找到 的方法type

呼叫者沒有存取 method的權限。

備註

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

此方法過載等同於呼叫 CreateDelegate(Type, Type, String, Boolean, Boolean) 方法過載,並指定 truethrowOnBindFailure

另請參閱

適用於

CreateDelegate(Type, Object, String, Boolean)

來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs

建立指定型別的委派,這個委派表示指定實例方法,以在具有指定大小寫的指定類別實例上叫用。

public:
 static Delegate ^ CreateDelegate(Type ^ type, System::Object ^ target, System::String ^ method, bool ignoreCase);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")]
public static Delegate CreateDelegate(Type type, object target, string method, bool ignoreCase);
public static Delegate CreateDelegate(Type type, object target, string method, bool ignoreCase);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")>]
static member CreateDelegate : Type * obj * string * bool -> Delegate
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

布爾值,指出比較方法名稱時是否忽略大小寫。

傳回

指定型別的委派,表示在指定的類別實例上叫用的指定實例方法。

屬性

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不繼承 MulticastDelegate

-或-

type 不是 RuntimeType

-或-

method 不是實例方法。

-或-

method 無法綁定,例如因為找不到。

Invoke未找到 的方法type

呼叫者沒有存取 method的權限。

備註

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

此方法過載等同於呼叫 CreateDelegate(Type, Object, String, Boolean, Boolean) 方法過載,並指定 truethrowOnBindFailure

另請參閱

適用於

CreateDelegate(Type, Object, MethodInfo, Boolean)

來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
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

a Object 是代表所代表方法的第一個論點。 針對實例方法,它必須與實例類型相容。

method
MethodInfo

描述 MethodInfo 代理所要表示的靜態或實例方法。

throwOnBindFailure
Boolean

true若無法method束縛,則拋出例外;否則,。 false

傳回

代表指定靜態或實例方法的指定類型代理,或 nullthrowOnBindFailurefalse 且代理無法綁定於 method

例外狀況

typenull

-或-

methodnull

type 不繼承 MulticastDelegate

-或-

type 不是 RuntimeType

-或-

method 不可被束縛,且 throwOnBindFailuretrue

-或-

method 不是 RuntimeMethodInfo

Invoke未找到 的方法type

呼叫者沒有存取 method的權限。

備註

這種方法過載以及 CreateDelegate(Type, Object, MethodInfo) 每次綁定失敗都會觸發的方法過載,提供了最靈活的代理式建立方式。 您可以使用它們來建立靜態或實例方法的委派,以及沒有第一個自變數。

注意

如果你沒有提供第一個參數,請使用 CreateDelegate(Type, MethodInfo, Boolean) 方法過載以提升效能。

欲了解更多資訊與範例,請參閱 System.Delegate.CreateDelegate 的補充 API 備註

另請參閱

適用於

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

來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
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);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")]
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
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")>]
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

表示 Typemethod作 的類別。

method
String

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

ignoreCase
Boolean

布爾值,指出比較方法名稱時是否忽略大小寫。

throwOnBindFailure
Boolean

true若無法method束縛,則拋出例外;否則,。 false

傳回

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

屬性

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不繼承 MulticastDelegate

-或-

type 不是 RuntimeType

-或-

target 不是 RuntimeType

-或-

target 是一種開放式通用型。 也就是說,其 ContainsGenericParameters 性質為 true

-或-

method 並非 static 方法(Visual Basic 中的 Shared 方法)。

-或-

method 無法被束縛,例如因為找不到,且 throwOnBindFailuretrue

Invoke未找到 的方法type

呼叫者沒有存取 method的權限。

備註

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

另請參閱

適用於

CreateDelegate(Type, MethodInfo, Boolean)

來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
Delegate.CoreCLR.cs
來源:
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

true若無法method束縛,則拋出例外;否則,。 false

傳回

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

例外狀況

typenull

-或-

methodnull

type 不繼承 MulticastDelegate

-或-

type 不是 RuntimeType

-或-

method 不可被束縛,且 throwOnBindFailuretrue

-或-

method 不是 RuntimeMethodInfo

Invoke未找到 的方法type

呼叫者沒有存取 method的權限。

備註

這個方法多載可以建立開放式靜態方法委派和開啟的實例方法委派 ,也就是公開實例方法之第一個隱藏自變數的委派。 詳細說明請參考更一般 CreateDelegate(Type, Object, MethodInfo, Boolean) 的方法過載,該模組允許你建立所有開放或封閉代理的組合,例如例如靜態方法。

注意

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

範例請參見 System.Delegate.CreateDelegate 的補充 API 備註

另請參閱

適用於

CreateDelegate(Type, Object, String)

來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs

建立指定型別的委派,此委派表示在指定的類別實例上叫用的指定實例方法。

public:
 static Delegate ^ CreateDelegate(Type ^ type, System::Object ^ target, System::String ^ method);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")]
public static Delegate CreateDelegate(Type type, object target, string method);
public static Delegate CreateDelegate(Type type, object target, string method);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")>]
static member CreateDelegate : Type * obj * string -> Delegate
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

-或-

method 不是實例方法。

-或-

method 無法綁定,例如因為找不到。

Invoke未找到 的方法type

呼叫者沒有存取 method的權限。

備註

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

此方法過載等同於呼叫CreateDelegate(Type, Object, String, Boolean, Boolean)方法過載,指定 false 為 和 ignoreCasetruethrowOnBindFailure

另請參閱

適用於

CreateDelegate(Type, Object, MethodInfo)

來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
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

-或-

method 無法被約束。

-或-

method 不是 RuntimeMethodInfo

Invoke未找到 的方法type

呼叫者沒有存取 method的權限。

備註

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

注意

如果你沒有提供第一個參數,就使用 CreateDelegate(Type, MethodInfo) 方法過載來提升效能。

欲了解更多關於此 API 的資訊,請參閱 System.Delegate.CreateDelegate 的補充 API 備註

另請參閱

適用於

CreateDelegate(Type, MethodInfo)

來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
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

-或-

method 無法被約束。

-或-

method 不是 RuntimeMethodInfo

Invoke未找到 的方法type

呼叫者沒有存取 method的權限。

備註

此多載可以建立靜態方法和開啟實例方法委派的委派;也就是說,明確提供實例方法隱藏的第一個自變數的委派。 詳細說明請參考更一般 CreateDelegate(Type, Object, MethodInfo) 的方法過載,該模組允許你建立所有開放或封閉代理的組合,例如範例或靜態方法,並可選擇指定第一個參數。

注意

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

欲了解更多關於此 API 的資訊,請參閱 System.Delegate.CreateDelegate 的補充 API 備註

另請參閱

適用於

CreateDelegate(Type, Type, String)

來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs
來源:
Delegate.cs

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

public:
 static Delegate ^ CreateDelegate(Type ^ type, Type ^ target, System::String ^ method);
public static Delegate CreateDelegate(Type type, Type target, string method);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")]
public static Delegate CreateDelegate(Type type, Type target, string method);
static member CreateDelegate : Type * Type * string -> Delegate
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The target method might be removed")>]
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

表示 Typemethod作 的類別。

method
String

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

傳回

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

屬性

例外狀況

typenull

-或-

targetnull

-或-

methodnull

type 不繼承 MulticastDelegate

-或-

type 不是 RuntimeType

-或-

target 不是 RuntimeType

-或-

target 是一種開放式通用型。 也就是說,其 ContainsGenericParameters 性質為 true

-或-

method 並非 static 方法(Visual Basic 中的 Shared 方法)。

Invoke未找到 的方法type

呼叫者沒有存取 method的權限。

備註

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

此方法過載等同於呼叫CreateDelegate(Type, Type, String, Boolean, Boolean)方法過載,指定 false 為 和 ignoreCasetruethrowOnBindFailure

另請參閱

適用於