Szerkesztés

Megosztás a következőn keresztül:


Delegate.CreateDelegate Method

Definition

Creates a delegate of the specified type.

Overloads

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

Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance, with the specified case-sensitivity and the specified behavior on failure to bind.

CreateDelegate(Type, Type, String, Boolean)

Creates a delegate of the specified type that represents the specified static method of the specified class, with the specified case-sensitivity.

CreateDelegate(Type, Object, String, Boolean)

Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance with the specified case-sensitivity.

CreateDelegate(Type, Object, MethodInfo, Boolean)

Creates a delegate of the specified type that represents the specified static or instance method, with the specified first argument and the specified behavior on failure to bind.

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

Creates a delegate of the specified type that represents the specified static method of the specified class, with the specified case-sensitivity and the specified behavior on failure to bind.

CreateDelegate(Type, MethodInfo, Boolean)

Creates a delegate of the specified type to represent the specified static method, with the specified behavior on failure to bind.

CreateDelegate(Type, Object, String)

Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance.

CreateDelegate(Type, Object, MethodInfo)

Creates a delegate of the specified type that represents the specified static or instance method, with the specified first argument.

CreateDelegate(Type, MethodInfo)

Creates a delegate of the specified type to represent the specified method.

CreateDelegate(Type, Type, String)

Creates a delegate of the specified type that represents the specified static method of the specified class.

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

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

Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance, with the specified case-sensitivity and the specified behavior on failure to bind.

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

Parameters

type
Type

The Type of delegate to create.

target
Object

The class instance on which method is invoked.

method
String

The name of the instance method that the delegate is to represent.

ignoreCase
Boolean

A Boolean indicating whether to ignore the case when comparing the name of the method.

throwOnBindFailure
Boolean

true to throw an exception if method cannot be bound; otherwise, false.

Returns

A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.

Exceptions

type is null.

-or-

target is null.

-or-

method is null.

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType. See Runtime Types in Reflection).

-or-

method is not an instance method.

-or-

method cannot be bound, for example because it cannot be found, and throwOnBindFailure is true.

The Invoke method of type is not found.

The caller does not have the permissions necessary to access method.

Remarks

This method creates delegates for instance methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

See also

Applies to

CreateDelegate(Type, Type, String, Boolean)

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

Creates a delegate of the specified type that represents the specified static method of the specified class, with the specified case-sensitivity.

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

Parameters

type
Type

The Type of delegate to create.

target
Type

The Type representing the class that implements method.

method
String

The name of the static method that the delegate is to represent.

ignoreCase
Boolean

A Boolean indicating whether to ignore the case when comparing the name of the method.

Returns

A delegate of the specified type that represents the specified static method of the specified class.

Exceptions

type is null.

-or-

target is null.

-or-

method is null.

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType. See Runtime Types in Reflection).

-or-

target is not a RuntimeType.

-or-

target is an open generic type. That is, its ContainsGenericParameters property is true.

-or-

method is not a static method (Shared method in Visual Basic).

-or-

method cannot be bound, for example because it cannot be found.

The Invoke method of type is not found.

The caller does not have the permissions necessary to access method.

Remarks

This method creates delegates for static methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

This method overload is equivalent to calling the CreateDelegate(Type, Type, String, Boolean, Boolean) method overload, specifying true for throwOnBindFailure.

See also

Applies to

CreateDelegate(Type, Object, String, Boolean)

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

Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance with the specified case-sensitivity.

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

Parameters

type
Type

The Type of delegate to create.

target
Object

The class instance on which method is invoked.

method
String

The name of the instance method that the delegate is to represent.

ignoreCase
Boolean

A Boolean indicating whether to ignore the case when comparing the name of the method.

Returns

A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.

Exceptions

type is null.

-or-

target is null.

-or-

method is null.

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType. See Runtime Types in Reflection).

-or-

method is not an instance method.

-or-

method cannot be bound, for example because it cannot be found.

The Invoke method of type is not found.

The caller does not have the permissions necessary to access method.

Remarks

This method creates delegates for instance methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

This method overload is equivalent to calling the CreateDelegate(Type, Object, String, Boolean, Boolean) method overload, specifying true for throwOnBindFailure.

See also

Applies to

CreateDelegate(Type, Object, MethodInfo, Boolean)

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

Creates a delegate of the specified type that represents the specified static or instance method, with the specified first argument and the specified behavior on failure to bind.

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

Parameters

type
Type

A Type representing the type of delegate to create.

firstArgument
Object

An Object that is the first argument of the method the delegate represents. For instance methods, it must be compatible with the instance type.

method
MethodInfo

The MethodInfo describing the static or instance method the delegate is to represent.

throwOnBindFailure
Boolean

true to throw an exception if method cannot be bound; otherwise, false.

Returns

A delegate of the specified type that represents the specified static or instance method, or null if throwOnBindFailure is false and the delegate cannot be bound to method.

Exceptions

type is null.

-or-

method is null.

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType. See Runtime Types in Reflection).

-or-

method cannot be bound, and throwOnBindFailure is true.

-or-

method is not a RuntimeMethodInfo. See Runtime Types in Reflection).

The Invoke method of type is not found.

The caller does not have the permissions necessary to access method.

Remarks

This method overload and the CreateDelegate(Type, Object, MethodInfo) method overload, which always throws on failure to bind, provide the most flexible way to create delegates. You can use them to create delegates for either static or instance methods, with or without a first argument.

Note

If you do not supply a first argument, use the CreateDelegate(Type, MethodInfo, Boolean) method overload for better performance.

For more information and examples, see Supplemental API remarks for System.Delegate.CreateDelegate.

See also

Applies to

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

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

Creates a delegate of the specified type that represents the specified static method of the specified class, with the specified case-sensitivity and the specified behavior on failure to bind.

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

Parameters

type
Type

The Type of delegate to create.

target
Type

The Type representing the class that implements method.

method
String

The name of the static method that the delegate is to represent.

ignoreCase
Boolean

A Boolean indicating whether to ignore the case when comparing the name of the method.

throwOnBindFailure
Boolean

true to throw an exception if method cannot be bound; otherwise, false.

Returns

A delegate of the specified type that represents the specified static method of the specified class.

Exceptions

type is null.

-or-

target is null.

-or-

method is null.

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType. See Runtime Types in Reflection).

-or-

target is not a RuntimeType.

-or-

target is an open generic type. That is, its ContainsGenericParameters property is true.

-or-

method is not a static method (Shared method in Visual Basic).

-or-

method cannot be bound, for example because it cannot be found, and throwOnBindFailure is true.

The Invoke method of type is not found.

The caller does not have the permissions necessary to access method.

Remarks

This method creates delegates for static methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

See also

Applies to

CreateDelegate(Type, MethodInfo, Boolean)

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

Creates a delegate of the specified type to represent the specified static method, with the specified behavior on failure to bind.

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

Parameters

type
Type

The Type of delegate to create.

method
MethodInfo

The MethodInfo describing the static or instance method the delegate is to represent.

throwOnBindFailure
Boolean

true to throw an exception if method cannot be bound; otherwise, false.

Returns

A delegate of the specified type to represent the specified static method.

Exceptions

type is null.

-or-

method is null.

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType. See Runtime Types in Reflection).

-or-

method cannot be bound, and throwOnBindFailure is true.

-or-

method is not a RuntimeMethodInfo. See Runtime Types in Reflection).

The Invoke method of type is not found.

The caller does not have the permissions necessary to access method.

Remarks

This method overload can create open static method delegates and open instance method delegates - that is, delegates that expose the hidden first argument of instance methods. For a detailed explanation, see the more general CreateDelegate(Type, Object, MethodInfo, Boolean) method overload, which allows you to create all combinations of open or closed delegates for instance or static methods.

Note

This method overload should be used when the delegate is not closed over its first argument, because it is somewhat faster in that case.

For examples, see Supplemental API remarks for System.Delegate.CreateDelegate.

See also

Applies to

CreateDelegate(Type, Object, String)

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

Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance.

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

Parameters

type
Type

The Type of delegate to create.

target
Object

The class instance on which method is invoked.

method
String

The name of the instance method that the delegate is to represent.

Returns

A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.

Exceptions

type is null.

-or-

target is null.

-or-

method is null.

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType. See Runtime Types in Reflection).

-or-

method is not an instance method.

-or-

method cannot be bound, for example because it cannot be found.

The Invoke method of type is not found.

The caller does not have the permissions necessary to access method.

Remarks

This method creates delegates for instance methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

This method overload is equivalent to calling the CreateDelegate(Type, Object, String, Boolean, Boolean) method overload, specifying false for ignoreCase and true for throwOnBindFailure.

See also

Applies to

CreateDelegate(Type, Object, MethodInfo)

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

Creates a delegate of the specified type that represents the specified static or instance method, with the specified first argument.

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

Parameters

type
Type

The Type of delegate to create.

firstArgument
Object

The object to which the delegate is bound, or null to treat method as static (Shared in Visual Basic).

method
MethodInfo

The MethodInfo describing the static or instance method the delegate is to represent.

Returns

A delegate of the specified type that represents the specified static or instance method.

Exceptions

type is null.

-or-

method is null.

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType. See Runtime Types in Reflection).

-or-

method cannot be bound.

-or-

method is not a RuntimeMethodInfo. See Runtime Types in Reflection).

The Invoke method of type is not found.

The caller does not have the permissions necessary to access method.

Remarks

Calling this method overload is equivalent to calling the CreateDelegate(Type, Object, MethodInfo, Boolean) method overload and specifying true for throwOnBindFailure. These two overloads provide the most flexible way to create delegates. You can use them to create delegates for either static or instance methods, and optionally to specify the first argument.

Note

If you don't supply a first argument, use the CreateDelegate(Type, MethodInfo) method overload for better performance.

For more information about this API, see Supplemental API remarks for System.Delegate.CreateDelegate.

See also

Applies to

CreateDelegate(Type, MethodInfo)

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

Creates a delegate of the specified type to represent the specified method.

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

Parameters

type
Type

The Type of delegate to create.

method
MethodInfo

The MethodInfo describing the static or instance method the delegate is to represent.

Returns

A delegate of the specified type to represent the specified method.

Exceptions

type is null.

-or-

method is null.

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType. See Runtime Types in Reflection).

-or-

method cannot be bound.

-or-

method is not a RuntimeMethodInfo. See Runtime Types in Reflection).

The Invoke method of type is not found.

The caller does not have the permissions necessary to access method.

Remarks

This overload can create delegates for static methods and open instance method delegates; that is, delegates that explicitly supply the hidden first argument of instance methods. For a detailed explanation, see the more general CreateDelegate(Type, Object, MethodInfo) method overload, which allows you to create all combinations of open or closed delegates for instance or static methods, and optionally to specify a first argument.

Note

This method overload should be used when the delegate is not closed over its first argument, because it is somewhat faster in that case.

For more information about this API, see Supplemental API remarks for System.Delegate.CreateDelegate.

See also

Applies to

CreateDelegate(Type, Type, String)

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

Creates a delegate of the specified type that represents the specified static method of the specified class.

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

Parameters

type
Type

The Type of delegate to create.

target
Type

The Type representing the class that implements method.

method
String

The name of the static method that the delegate is to represent.

Returns

A delegate of the specified type that represents the specified static method of the specified class.

Exceptions

type is null.

-or-

target is null.

-or-

method is null.

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType. See Runtime Types in Reflection).

-or-

target is not a RuntimeType.

-or-

target is an open generic type. That is, its ContainsGenericParameters property is true.

-or-

method is not a static method (Shared method in Visual Basic).

The Invoke method of type is not found.

The caller does not have the permissions necessary to access method.

Remarks

This method creates delegates for static methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

This method overload is equivalent to calling the CreateDelegate(Type, Type, String, Boolean, Boolean) method overload, specifying false for ignoreCase and true for throwOnBindFailure.

See also

Applies to