Exporter (0) Imprimer
Développer tout
EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

ParameterModifier Structure

Attaches a modifier to parameters so that binding can work with parameter signatures in which the types have been modified.

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

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public struct ParameterModifier
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class ParameterModifier extends ValueType
Not applicable.

The ParameterModifier structure is used with the Type.InvokeMember method overload when passing parameters by reference to a COM component that is accessed late bound. 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. The single ParameterModifier structure in this array must be initialized with the number of parameters in the member that is to be invoked. To indicate which of these parameters are passed by reference, set the value of the Item property (the indexer in C#) to true for the index number corresponding to the zero-based position of the parameter.

The following code example shows this for a member that has three string arguments, the first and third of which are passed by reference. Assume that a variable named obj contains a reference to the COM object.

    ' 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)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Ajouts de la communauté

AJOUTER
Microsoft réalise une enquête en ligne pour recueillir votre opinion sur le site Web de MSDN. Si vous choisissez d’y participer, cette enquête en ligne vous sera présentée lorsque vous quitterez le site Web de MSDN.

Si vous souhaitez y participer,
Afficher:
© 2014 Microsoft