ParameterModifier 結構

定義

將修飾詞附加到參數,如此一來,繫結就能與已修改類型的參數簽章一同運作。Attaches a modifier to parameters so that binding can work with parameter signatures in which the types have been modified.

public value class ParameterModifier
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct ParameterModifier
type ParameterModifier = struct
Public Structure ParameterModifier
繼承
ParameterModifier
屬性

範例

下列程式碼範例顯示具有三個字串引數的成員, 其中第一個和第三個是以傳址方式傳遞。The following code example shows this for a member that has three string arguments, the first and third of which are passed by reference. 假設名為obj的變數包含 COM 物件的參考。Assume that a variable named obj contains a reference to the COM object.

// Create an array containing the arguments.
array<Object^>^ args = {"Argument 1", "Argument 2", "Argument 3" };

// Initialize a ParameterModifier with the number of parameters.
ParameterModifier p = ParameterModifier(3);

// Pass the first and third parameters by reference.
p[0] = true;
p[2] = true;

// The ParameterModifier must be passed as the single element
// of an array.

array<ParameterModifier>^ mods = { p };

// Invoke the method late bound.
obj->GetType()->InvokeMember("MethodName", BindingFlags::InvokeMethod,
     nullptr, obj, args, mods, nullptr, nullptr);
// Create an array containing the arguments.
object[] args = {"Argument 1", "Argument 2", "Argument 3" };

// Initialize a ParameterModifier with the number of parameters.
ParameterModifier p = new ParameterModifier(3);

// Pass the first and third parameters by reference.
p[0] = true;
p[2] = true;

// The ParameterModifier must be passed as the single element
// of an array.
ParameterModifier[] mods = { p };

// Invoke the method late bound.
obj.GetType().InvokeMember("MethodName", BindingFlags.InvokeMethod,
     null, obj, args, mods, null, null);
' Create an array containing the arguments.
Dim args As Object = {"Argument 1", "Argument 2", "Argument 3" }

' Initialize a ParameterModifier with the number of parameters.
Dim p As New ParameterModifier(3)

' Pass the first and third parameters by reference.
p(0) = True
p(2) = True

' The ParameterModifier must be passed as the single element
' of an array.
Dim mods() As ParameterModifier = { p }

' Invoke the method late bound.
obj.GetType().InvokeMember("MethodName", BindingFlags.InvokeMethod, _
     Nothing, obj, args, mods, Nothing, Nothing)

備註

當以傳址方式將Type.InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])參數傳遞至晚期繫結存取的 COM 元件時, 會使用此結構搭配方法多載。ParameterModifierThe ParameterModifier structure is used with the Type.InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]) method overload when passing parameters by reference to a COM component that is accessed late bound. 要以傳址方式傳遞的參數是由單一ParameterModifier結構所指定, 它必須在包含單一元素的陣列中傳遞。The parameters that are to be passed by reference are specified by a single ParameterModifier structure, which must be passed in an array containing a single element. 此陣列ParameterModifier中的單一結構必須以要叫用之成員中的參數數目來初始化。The single ParameterModifier structure in this array must be initialized with the number of parameters in the member that is to be invoked. 若要指出哪些參數是以傳址方式傳遞, 請將Item[Int32]屬性的值 (中C#的索引子) true設定為, 以取得對應至參數之以零為起始位置的索引編號。To indicate which of these parameters are passed by reference, set the value of the Item[Int32] property (the indexer in C#) to true for the index number corresponding to the zero-based position of the parameter.

建構函式

ParameterModifier(Int32)

初始化 ParameterModifier 結構的新執行個體,代表指定的參數數目。Initializes a new instance of the ParameterModifier structure representing the specified number of parameters.

屬性

Item[Int32]

取得或設定值,指定位於指定索引位置的參數是否要由目前的 ParameterModifier 所修改。Gets or sets a value that specifies whether the parameter at the specified index position is to be modified by the current ParameterModifier.

適用於