Delegate.CreateDelegate Method (Type, Type, String, Boolean, Boolean)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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.

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

Syntax

Public Shared Function CreateDelegate ( _
    type As Type, _
    target As Type, _
    method As String, _
    ignoreCase As Boolean, _
    throwOnBindFailure As Boolean _
) As Delegate
public static Delegate CreateDelegate(
    Type type,
    Type target,
    string method,
    bool ignoreCase,
    bool throwOnBindFailure
)

Parameters

  • method
    Type: System..::.String
    The name of the static method that the delegate is to represent.
  • ignoreCase
    Type: System..::.Boolean
    true to ignore the case when comparing the name of the method; otherwise, false.
  • throwOnBindFailure
    Type: System..::.Boolean
    true to throw an exception if method cannot be bound; otherwise, false.

Return Value

Type: System..::.Delegate
A delegate of the specified type that represents the specified static method of the specified class.

Exceptions

Exception Condition
ArgumentNullException

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

-or-

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

-or-

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

ArgumentException

type does not inherit MulticastDelegate.

-or-

type is not a RuntimeType.

-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.

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 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.

method must specify an accessible method.

Platform Notes

 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

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

See Also

Reference

Delegate Class

CreateDelegate Overload

System Namespace

Type

MulticastDelegate

Object