Share via


DynamicMethod.DefineParameter(Int32, ParameterAttributes, String) 方法

定義

定義動態方法的參數。

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

參數

position
Int32

在參數清單中參數的位置。 第一個參數的參數索引從數字 1 開始。

attributes
ParameterAttributes

指定參數屬性的 ParameterAttributes 值的位元組合。

parameterName
String

參數名稱。 名稱可以是零長度字串。

傳回

一律傳回 null

例外狀況

這個方法沒有參數。

-或-

position 小於 0。

-或-

position 大於方法參數的數目。

範例

下列程式代碼範例示範如何定義動態方法的參數資訊。 此程式代碼範例是提供給 類別之較大範例的 DynamicMethod 一部分。

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

備註

如果 position 為 0,則 DefineParameter 方法會參考傳回值。 設定參數資訊不會影響傳回值。

如果已經完成動態方法,藉由呼叫 CreateDelegateInvoke 方法,方法 DefineParameter 就不會有任何作用。 不會擲回任何例外狀況。

適用於