Get a constructor by parameters and modifiers in CSharp
Description
The following code shows how to get a constructor by parameters and modifiers.
Example
using System;/*from w w w. ja v a2 s . com*/
using System.Reflection;
using System.Security;
public class MyClass1
{
public MyClass1(int i){}
public static void Main()
{
Type myType = typeof(MyClass1);
Type[] types = new Type[1];
types[0] = typeof(int);
ConstructorInfo constructorInfoObj = myType.GetConstructor(
BindingFlags.Instance | BindingFlags.Public, null, types, null);
if (constructorInfoObj != null )
{
Console.WriteLine("The constructor of MyClass1 that is public " +
"and takes an integer as a parameter is:");
Console.WriteLine(constructorInfoObj.ToString());
}
}
}
The code above generates the following result.