Export (0) Print
Expand All

MethodBuilder.GetParameters Method

Returns the parameters of this method.

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

public override ParameterInfo[] GetParameters ()
public ParameterInfo[] GetParameters ()
public override function GetParameters () : ParameterInfo[]
Not applicable.

Return Value

An array of ParameterInfo objects that represent the parameters of the method.

Exception typeCondition

NotSupportedException

This method is not currently supported. Retrieve the method using GetMethod and call GetParameters on the returned MethodInfo.

The code sample below illustrates the use of GetParameters to discover information on the parameters passed to a dynamically-generated method.


TypeBuilder myType1 = myModBuilder.DefineType("MyMathFunctions",
                TypeAttributes.Public);

MethodBuilder myMthdBuilder = myType1.DefineMethod("AddToRefValue",
                MethodAttributes.Public,
                typeof(void),
                new Type[] { Type.GetType("System.Int32&"),
                         typeof(int) });
ParameterBuilder myParam1 = myMthdBuilder.DefineParameter(1,
                ParameterAttributes.Out,
                "thePool");
ParameterBuilder myParam2 = myMthdBuilder.DefineParameter(2,
                ParameterAttributes.In,
                "addMeToPool");

// Create body via ILGenerator here, and complete the type.

ParameterInfo[] myParams = myMthdBuilder.GetParameters();

Console.WriteLine("Method: {0}", myMthdBuilder.Name);

foreach (ParameterInfo myParam in myParams)
    {
   Console.WriteLine("------- Parameter: {0} {1} at pos {2}, with attribute {3}", 
             myParam.ParameterType, myParam.Name, myParam.Position,
             myParam.Attributes.ToString());

    }


TypeBuilder myType1 = myModBuilder.DefineType("MyMathFunctions",
    TypeAttributes.Public);
MethodBuilder myMthdBuilder = myType1.DefineMethod("AddToRefValue",
    MethodAttributes.Public, Void.class.ToType(),
    new Type[] { Type.GetType("System.Int32&"), int.class.ToType() });
ParameterBuilder myParam1 = myMthdBuilder.DefineParameter(1,
    ParameterAttributes.Out, "thePool");
ParameterBuilder myParam2 = myMthdBuilder.DefineParameter(2,
    ParameterAttributes.In, "addMeToPool");

// Create body via ILGenerator here, and complete the type.
ParameterInfo myParams[] = myMthdBuilder.GetParameters();
Console.WriteLine("Method: {0}", myMthdBuilder.get_Name());
for (int iCtr = 0; iCtr < myParams.length; iCtr++) {
    ParameterInfo myParam = myParams[iCtr];
    Console.WriteLine(
        "------- Parameter: {0} {1} at pos {2},with attribute {3}",
        new Object[] { myParam.get_ParameterType(), myParam.get_Name(),
        System.Convert.ToString(myParam.get_Position()),
        myParam.get_Attributes().ToString() });
}

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, 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

Community Additions

ADD
Show:
© 2015 Microsoft