DynamicMethod.DefineParameter(Int32, ParameterAttributes, String) Method

Definition

Defines a parameter of the dynamic method.

public:
 System::Reflection::Emit::ParameterBuilder ^ DefineParameter(int position, System::Reflection::ParameterAttributes attributes, System::String ^ parameterName);
public System.Reflection.Emit.ParameterBuilder? DefineParameter (int position, System.Reflection.ParameterAttributes attributes, string? parameterName);
public System.Reflection.Emit.ParameterBuilder DefineParameter (int position, System.Reflection.ParameterAttributes attributes, string parameterName);
member this.DefineParameter : int * System.Reflection.ParameterAttributes * string -> System.Reflection.Emit.ParameterBuilder
Public Function DefineParameter (position As Integer, attributes As ParameterAttributes, parameterName As String) As ParameterBuilder

Parameters

position
Int32

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

attributes
ParameterAttributes

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

parameterName
String

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

Returns

ParameterBuilder

Always returns null.

Exceptions

The method has no parameters.

-or-

position is less than 0.

-or-

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

Examples

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");
// 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");
' 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")

Remarks

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.

Applies to