次の方法で共有


Delegate.CreateDelegate Method (Type, Object, String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared Function CreateDelegate ( _
    type As Type, _
    target As Object, _
    method As String _
) As Delegate
public static Delegate CreateDelegate(
    Type type,
    Object target,
    string method
)

Parameters

  • type
    Type: System.Type
    The type of delegate to create.
  • target
    Type: System.Object
    The class instance on which method is invoked.
  • method
    Type: System.String
    The name of the instance method that the delegate is to represent.

Return Value

Type: System.Delegate
A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.

Exceptions

Exception Condition
ArgumentNullException

type is nulla null reference (Nothing in Visual Basic).

-or-

target is nulla null reference (Nothing in Visual Basic).

-or-

method is nulla null reference (Nothing in Visual Basic).

ArgumentException

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.

MissingMethodException

The Invoke method of type is not found.

MethodAccessException

The caller does not have access to method.

-or-

Application code attempts to access this member late-bound, for example, by using the Type.InvokeMember 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.

In Silverlight, method must specify an accessible method.

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

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 CreateDelegate throws MissingMethodException when attempting to create a delegate with incorrect arguments. Delegate.CreateDelegate throws TargetInvocationException when called on a null object. Delegate.CreateDelegate throws MissingMethodException instead of ArgumentException for non-instance methods.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.