Export (0) Print
Expand All

DynamicMethod.CreateDelegate Method (Type)

Completes the dynamic method and creates a delegate that can be used to execute it.

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

[<ComVisibleAttribute(true)>]
abstract CreateDelegate : 
        delegateType:Type -> Delegate 
[<ComVisibleAttribute(true)>]
override CreateDelegate : 
        delegateType:Type -> Delegate

Parameters

delegateType
Type: System.Type

A delegate type whose signature matches that of the dynamic method.

Return Value

Type: System.Delegate
A delegate of the specified type, which can be used to execute the dynamic method.

ExceptionCondition
InvalidOperationException

The dynamic method has no method body.

ArgumentException

delegateType has the wrong number of parameters or the wrong parameter types.

Calling the CreateDelegate method or the Invoke method completes the dynamic method. Any further attempt to alter the dynamic method, such as modifying parameter definitions or emitting more Microsoft intermediate language (MSIL), is ignored; no exception is thrown.

To create a method body for a dynamic method when you have your own MSIL generator, call the GetDynamicILInfo method to obtain a DynamicILInfo object. If you do not have your own MSIL generator, call the GetILGenerator method to obtain an ILGenerator object that can be used to generate the method body.

The following code example creates a dynamic method that takes two parameters. The example emits a simple function body that prints the first parameter to the console, and the example uses the second parameter as the return value of the method. The example completes the method by creating a delegate, invokes the delegate with different parameters, and finally invokes the dynamic method using the Invoke method.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft