Delegate.CreateDelegate 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立指定型別的委派。
多載
| 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)
建立指定型別的委派,這個委派表示指定類別實例上要叫用的指定實例方法,並具有指定的區分大小寫,以及無法系結的指定行為。
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
參數
- target
- Object
叫用 method 的類別實例。
- method
- String
委派要表示的實例方法名稱。
- ignoreCase
- Boolean
布爾值,指出比較方法名稱時是否忽略大小寫。
- throwOnBindFailure
- Boolean
如果無法繫結 method,true 擲回例外狀況;否則,false。
傳回
指定型別的委派,表示在指定的類別實例上叫用的指定實例方法。
例外狀況
type 不會繼承 MulticastDelegate。
-或-
type 不是 RuntimeType。 請參閱反映中的
-或-
method 不是實例方法。
-或-
method 無法繫結,例如找不到,且 throwOnBindFailuretrue。
找不到 type 的 Invoke 方法。
呼叫端沒有存取 method所需的許可權。
備註
這個方法只會建立實例方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。
另請參閱
適用於
CreateDelegate(Type, Type, String, Boolean)
- 來源:
- 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);
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
參數
- method
- String
委派要表示的靜態方法名稱。
- ignoreCase
- Boolean
布爾值,指出比較方法名稱時是否忽略大小寫。
傳回
指定型別的委派,表示指定類別的指定靜態方法。
例外狀況
type 不會繼承 MulticastDelegate。
-或-
type 不是 RuntimeType。 請參閱反映中的
-或-
target 不是 RuntimeType。
-或-
target 是開放式泛型類型。 也就是說,其 ContainsGenericParameters 屬性 true。
-或-
method 不是 static 方法(Visual Basic 中的Shared 方法)。
-或-
method 無法系結,例如找不到。
找不到 type 的 Invoke 方法。
呼叫端沒有存取 method所需的許可權。
備註
這個方法只會建立靜態方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。
這個方法多載相當於呼叫 CreateDelegate(Type, Type, String, Boolean, Boolean) 方法多載,並指定 throwOnBindFailure的 true。
另請參閱
適用於
CreateDelegate(Type, Object, String, Boolean)
- 來源:
- Delegate.cs
- 來源:
- Delegate.cs
- 來源:
- 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
參數
- target
- Object
叫用 method 的類別實例。
- method
- String
委派要表示的實例方法名稱。
- ignoreCase
- Boolean
布爾值,指出比較方法名稱時是否忽略大小寫。
傳回
指定型別的委派,表示在指定的類別實例上叫用的指定實例方法。
例外狀況
type 不會繼承 MulticastDelegate。
-或-
type 不是 RuntimeType。 請參閱反映中的
-或-
method 不是實例方法。
-或-
method 無法系結,例如找不到。
找不到 type 的 Invoke 方法。
呼叫端沒有存取 method所需的許可權。
備註
這個方法只會建立實例方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。
這個方法多載相當於呼叫 CreateDelegate(Type, Object, String, Boolean, Boolean) 方法多載,並指定 throwOnBindFailure的 true。
另請參閱
適用於
CreateDelegate(Type, Object, MethodInfo, Boolean)
建立代表指定之靜態或實例方法之指定型別的委派,其中具有指定的第一個自變數,以及無法系結的指定行為。
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
參數
- method
- MethodInfo
描述委派所代表之靜態或實例方法的 MethodInfo。
- throwOnBindFailure
- Boolean
如果無法繫結 method,true 擲回例外狀況;否則,false。
傳回
表示指定之靜態或實例方法之指定型別的委派,如果 throwOnBindFailurefalse 且委派無法系結至 method,則 null。
例外狀況
type 不會繼承 MulticastDelegate。
-或-
type 不是 RuntimeType。 請參閱反映中的
-或-
無法繫結 method,而且 throwOnBindFailuretrue。
-或-
method 不是 RuntimeMethodInfo。 請參閱反映中的
找不到 type 的 Invoke 方法。
呼叫端沒有存取 method所需的許可權。
備註
這個方法多載和 CreateDelegate(Type, Object, MethodInfo) 方法多載,一律會在無法系結時擲回,提供最靈活的方法來建立委派。 您可以使用它們來建立靜態或實例方法的委派,以及沒有第一個自變數。
注意
如果您沒有提供第一個自變數,請使用 CreateDelegate(Type, MethodInfo, Boolean) 方法多載來提升效能。
如需詳細資訊和範例,請參閱 System.Delegate.CreateDelegate的補充 API 備註。
另請參閱
適用於
CreateDelegate(Type, Type, String, Boolean, Boolean)
建立指定型別的委派,此委派表示指定類別的指定靜態方法,具有指定的區分大小寫,以及無法系結的指定行為。
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
參數
- method
- String
委派要表示的靜態方法名稱。
- ignoreCase
- Boolean
布爾值,指出比較方法名稱時是否忽略大小寫。
- throwOnBindFailure
- Boolean
如果無法繫結 method,true 擲回例外狀況;否則,false。
傳回
指定型別的委派,表示指定類別的指定靜態方法。
例外狀況
type 不會繼承 MulticastDelegate。
-或-
type 不是 RuntimeType。 請參閱反映中的
-或-
target 不是 RuntimeType。
-或-
target 是開放式泛型類型。 也就是說,其 ContainsGenericParameters 屬性 true。
-或-
method 不是 static 方法(Visual Basic 中的Shared 方法)。
-或-
method 無法繫結,例如找不到,且 throwOnBindFailuretrue。
找不到 type 的 Invoke 方法。
呼叫端沒有存取 method所需的許可權。
備註
這個方法只會建立靜態方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。
另請參閱
適用於
CreateDelegate(Type, MethodInfo, Boolean)
建立指定型別的委派,以表示指定的靜態方法,並在無法系結時指定的行為。
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
參數
- method
- MethodInfo
描述委派所代表之靜態或實例方法的 MethodInfo。
- throwOnBindFailure
- Boolean
如果無法繫結 method,true 擲回例外狀況;否則,false。
傳回
表示指定之靜態方法之指定型別的委派。
例外狀況
type 不會繼承 MulticastDelegate。
-或-
type 不是 RuntimeType。 請參閱反映中的
-或-
無法繫結 method,而且 throwOnBindFailuretrue。
-或-
method 不是 RuntimeMethodInfo。 請參閱反映中的
找不到 type 的 Invoke 方法。
呼叫端沒有存取 method所需的許可權。
備註
這個方法多載可以建立開放式靜態方法委派和開啟的實例方法委派 ,也就是公開實例方法之第一個隱藏自變數的委派。 如需詳細說明,請參閱更一般 CreateDelegate(Type, Object, MethodInfo, Boolean) 方法多載,這可讓您建立實例或靜態方法之開啟或關閉委派的所有組合。
注意
當委派未在其第一個自變數上關閉時,應該使用這個方法多載,因為在此情況下會比較快一些。
如需範例,請參閱 System.Delegate.CreateDelegate的補充 API 備註。
另請參閱
適用於
CreateDelegate(Type, Object, String)
- 來源:
- Delegate.cs
- 來源:
- Delegate.cs
- 來源:
- 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
參數
- target
- Object
叫用 method 的類別實例。
- method
- String
委派要表示的實例方法名稱。
傳回
指定型別的委派,表示在指定的類別實例上叫用的指定實例方法。
例外狀況
type 不會繼承 MulticastDelegate。
-或-
type 不是 RuntimeType。 請參閱反映中的
-或-
method 不是實例方法。
-或-
method 無法系結,例如找不到。
找不到 type 的 Invoke 方法。
呼叫端沒有存取 method所需的許可權。
備註
這個方法只會建立實例方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。
這個方法多載相當於呼叫 CreateDelegate(Type, Object, String, Boolean, Boolean) 方法多載,並針對 throwOnBindFailure指定 ignoreCase 和 truefalse。
另請參閱
適用於
CreateDelegate(Type, Object, MethodInfo)
- 來源:
- 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
參數
- firstArgument
- Object
委派系結的物件,或 null 將 method 視為 static (在Visual Basic中為Shared)。
- method
- MethodInfo
描述委派所代表之靜態或實例方法的 MethodInfo。
傳回
表示指定之靜態或實例方法之指定型別的委派。
例外狀況
type 不會繼承 MulticastDelegate。
-或-
type 不是 RuntimeType。 請參閱反映中的
-或-
無法繫結 method。
-或-
method 不是 RuntimeMethodInfo。 請參閱反映中的
找不到 type 的 Invoke 方法。
呼叫端沒有存取 method所需的許可權。
備註
呼叫這個方法多載相當於呼叫 CreateDelegate(Type, Object, MethodInfo, Boolean) 方法多載,並指定 throwOnBindFailure的 true。 這兩個多載提供最有彈性的方式來建立委派。 您可以使用它們來建立靜態或實例方法的委派,並選擇性地指定第一個自變數。
注意
如果您沒有提供第一個自變數,請使用 CreateDelegate(Type, MethodInfo) 方法多載來提升效能。
如需此 API 的詳細資訊,請參閱 System.Delegate.CreateDelegate的補充 API 備註。
另請參閱
適用於
CreateDelegate(Type, MethodInfo)
- 來源:
- 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
參數
- method
- MethodInfo
描述委派所代表之靜態或實例方法的 MethodInfo。
傳回
表示指定方法之指定型別的委派。
例外狀況
type 不會繼承 MulticastDelegate。
-或-
type 不是 RuntimeType。 請參閱反映中的
-或-
無法繫結 method。
-或-
method 不是 RuntimeMethodInfo。 請參閱反映中的
找不到 type 的 Invoke 方法。
呼叫端沒有存取 method所需的許可權。
備註
此多載可以建立靜態方法和開啟實例方法委派的委派;也就是說,明確提供實例方法隱藏的第一個自變數的委派。 如需詳細說明,請參閱更一般 CreateDelegate(Type, Object, MethodInfo) 方法多載,這可讓您建立實例或靜態方法之開啟或關閉委派的所有組合,並選擇性地指定第一個自變數。
注意
當委派未在其第一個自變數上關閉時,應該使用這個方法多載,因為在此情況下會比較快一些。
如需此 API 的詳細資訊,請參閱 System.Delegate.CreateDelegate的補充 API 備註。
另請參閱
適用於
CreateDelegate(Type, Type, String)
- 來源:
- 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);
static member CreateDelegate : Type * Type * string -> Delegate
Public Shared Function CreateDelegate (type As Type, target As Type, method As String) As Delegate
參數
- method
- String
委派要表示的靜態方法名稱。
傳回
指定型別的委派,表示指定類別的指定靜態方法。
例外狀況
type 不會繼承 MulticastDelegate。
-或-
type 不是 RuntimeType。 請參閱反映中的
-或-
target 不是 RuntimeType。
-或-
target 是開放式泛型類型。 也就是說,其 ContainsGenericParameters 屬性 true。
-或-
method 不是 static 方法(Visual Basic 中的Shared 方法)。
找不到 type 的 Invoke 方法。
呼叫端沒有存取 method所需的許可權。
備註
這個方法只會建立靜態方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。
這個方法多載相當於呼叫 CreateDelegate(Type, Type, String, Boolean, Boolean) 方法多載,並針對 throwOnBindFailure指定 ignoreCase 和 truefalse。