ConstructorBuilder.GetParameters Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Returns the parameters of this constructor.

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

public override ParameterInfo[] GetParameters()

Return Value

Type: System.Reflection.ParameterInfo[]

Returns an array of ParameterInfo objects that represent the parameters of this constructor.

Exception Condition

CreateType has not been called on this constructor's type, in the .NET Framework versions 1.0 and 1.1.


CreateType has not been called on this constructor's type, in the .NET Framework version 2.0.

This property is not supported until after the TypeBuilder.CreateType method has been called. In the .NET Framework versions 1.0 and 1.1, InvalidOperationException is thrown. In the .NET Framework version 2.0, NotSupportedException is thrown.

The code sample illustrates the use of GetParameters.

// Define a constructor of the dynamic class.
ConstructorBuilder myConstructorBuilder = myTypeBuilder.DefineConstructor(
   MethodAttributes.Public, CallingConventions.Standard, myConstructorArgs);
// Get a reference to the module that contains this constructor.
Module myModule = myConstructorBuilder.GetModule();
Console.WriteLine("Module Name : " + myModule.Name);
// Get the 'MethodToken' that represents the token for this constructor.
MethodToken myMethodToken = myConstructorBuilder.GetToken();
Console.WriteLine("Constructor Token is : " + myMethodToken.Token);
// Get the method implementation flags for this constructor.
MethodImplAttributes myMethodImplAttributes = myConstructorBuilder.GetMethodImplementationFlags();
Console.WriteLine("MethodImplAttributes : "  + myMethodImplAttributes);
// Generate IL for the method, call its base class constructor and store the arguments
// in the private field.
ILGenerator myILGenerator3 = myConstructorBuilder.GetILGenerator();
ConstructorInfo myConstructorInfo = typeof(Object).GetConstructor(new Type[0]);
myILGenerator3.Emit(OpCodes.Call, myConstructorInfo);
myILGenerator3.Emit(OpCodes.Stfld, myGreetingField);
// Add a method to the type.
myMethodBuilder = myTypeBuilder.DefineMethod
// Generate IL for the method.
ILGenerator myILGenerator2 = myMethodBuilder.GetILGenerator();
myILGenerator2.EmitWriteLine("Hello World from global");
myType1 = myTypeBuilder.CreateType();

// Get the parameters of this constructor.
ParameterInfo[] myParameterInfo = myConstructorBuilder.GetParameters();
for(int i =0 ; i < myParameterInfo.Length; i++)
   Console.WriteLine("Declaration type : " + myParameterInfo[i].Member.DeclaringType);

.NET Framework
Available since 1.1
Available since 2.0
Return to top