Export (0) Print
Expand All

DynamicMethod Constructor (String, MethodAttributes, CallingConventions, Type, Type[], Module, Boolean)

Creates a dynamic method that is global to a module, specifying the method name, attributes, calling convention, return type, parameter types, module, and whether just-in-time (JIT) visibility checks should be skipped for types and members accessed by the Microsoft intermediate language (MSIL) of the dynamic method.

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

public DynamicMethod(
	string name,
	MethodAttributes attributes,
	CallingConventions callingConvention,
	Type returnType,
	Type[] parameterTypes,
	Module m,
	bool skipVisibility
)

Parameters

name
Type: System.String

The name of the dynamic method. This can be a zero-length string, but it cannot be null.

attributes
Type: System.Reflection.MethodAttributes

A bitwise combination of MethodAttributes values that specifies the attributes of the dynamic method. The only combination allowed is Public and Static.

callingConvention
Type: System.Reflection.CallingConventions

The calling convention for the dynamic method. Must be Standard.

returnType
Type: System.Type

A Type object that specifies the return type of the dynamic method, or null if the method has no return type.

parameterTypes
Type: System.Type[]

An array of Type objects specifying the types of the parameters of the dynamic method, or null if the method has no parameters.

m
Type: System.Reflection.Module

A Module representing the module with which the dynamic method is to be logically associated.

skipVisibility
Type: System.Boolean

true to skip JIT visibility checks on types and members accessed by the MSIL of the dynamic method; otherwise, false.

ExceptionCondition
ArgumentException

An element of parameterTypes is null or Void.

-or-

m is a module that provides anonymous hosting for dynamic methods.

ArgumentNullException

name is null.

-or-

m is null.

NotSupportedException

attributes is a combination of flags other than Public and Static.

-or-

callingConvention is not Standard.

-or-

returnType is a type for which Type.IsByRef returns true.

The dynamic method created with this constructor has access to public and internal (Friend in Visual Basic) members of all the public and internal types contained in module m.

Skipping the JIT compiler's visibility checks allows the dynamic method to access private and protected members of all other types in the module and in all other assemblies as well. This is useful, for example, when writing code to serialize objects.

NoteNote

For backward compatibility, this constructor demands SecurityPermission with the SecurityPermissionFlag.ControlEvidence flag if the following conditions are both true: m is a module other than the calling module, and the demand for ReflectionPermission with the ReflectionPermissionFlag.MemberAccess flag has failed. If the demand for SecurityPermission succeeds, the operation is allowed.

NoteNote

Starting with the .NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5 or later.

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: 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