Export (0) Print
Expand All

DynamicMethod.DefineParameter Method

Defines a parameter of the dynamic method.

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

public ParameterBuilder DefineParameter(
	int position,
	ParameterAttributes attributes,
	string parameterName


Type: System.Int32

The position of the parameter in the parameter list. Parameters are indexed beginning with the number 1 for the first parameter.

Type: System.Reflection.ParameterAttributes

A bitwise combination of ParameterAttributes values that specifies the attributes of the parameter.

Type: System.String

The name of the parameter. The name can be a zero-length string.

Return Value

Type: System.Reflection.Emit.ParameterBuilder
Always returns null.


The method has no parameters.


position is less than 0.


position is greater than the number of the method's parameters.

If position is 0, the DefineParameter method refers to the return value. Setting parameter information has no effect on the return value.

If the dynamic method has already been completed, by calling the CreateDelegate or Invoke method, the DefineParameter method has no effect. No exception is thrown.

The following code example shows how to define parameter information for a dynamic method. This code example is part of a larger example provided for the DynamicMethod class.

// Add parameter information to the dynamic method. (This is not 
// necessary, but can be useful for debugging.) For each parameter, 
// identified by position, supply the parameter attributes and a  
// parameter name.
hello.DefineParameter(1, ParameterAttributes.In, "message");
hello.DefineParameter(2, ParameterAttributes.In, "valueToReturn");

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

© 2014 Microsoft