ConstructorBuilder.GetParameters Method
.NET Framework 3.0
Returns the parameters of this constructor.
Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)
Assembly: mscorlib (in mscorlib.dll)
| Exception type | 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. |
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(); myILGenerator3.Emit(OpCodes.Ldarg_0); ConstructorInfo myConstructorInfo = typeof(Object).GetConstructor(new Type[0]); myILGenerator3.Emit(OpCodes.Call, myConstructorInfo); myILGenerator3.Emit(OpCodes.Ldarg_0); myILGenerator3.Emit(OpCodes.Ldarg_1); myILGenerator3.Emit(OpCodes.Stfld, myGreetingField); myILGenerator3.Emit(OpCodes.Ret); // Add a method to the type. myMethodBuilder = myTypeBuilder.DefineMethod ("HelloWorld",MethodAttributes.Public,null,null); // Generate IL for the method. ILGenerator myILGenerator2 = myMethodBuilder.GetILGenerator(); myILGenerator2.EmitWriteLine("Hello World from global"); myILGenerator2.Emit(OpCodes.Ret); myModuleBuilder.CreateGlobalFunctions(); 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); }
// 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.get_Name());
// Get the 'MethodToken' that represents the token for this constructor.
MethodToken myMethodToken = myConstructorBuilder.GetToken();
Console.WriteLine("Constructor Token is : " + myMethodToken.get_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();
myILGenerator3.Emit(OpCodes.Ldarg_0);
ConstructorInfo myConstructorInfo =
Object.class.ToType().GetConstructor(new Type[0]);
myILGenerator3.Emit(OpCodes.Call, myConstructorInfo);
myILGenerator3.Emit(OpCodes.Ldarg_0);
myILGenerator3.Emit(OpCodes.Ldarg_1);
myILGenerator3.Emit(OpCodes.Stfld, myGreetingField);
myILGenerator3.Emit(OpCodes.Ret);
// Add a method to the type.
myMethodBuilder =
myTypeBuilder.DefineMethod("HelloWorld", MethodAttributes.Public,
null, null);
// Generate IL for the method.
ILGenerator myILGenerator2 = myMethodBuilder.GetILGenerator();
myILGenerator2.EmitWriteLine("Hello World from global");
myILGenerator2.Emit(OpCodes.Ret);
myModuleBuilder.CreateGlobalFunctions();
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].get_Member().get_DeclaringType());
}
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.