Mega Code Archive

 
Categories / C# / Reflection
 

Searches for a constructor whose parameters match the specified argument types and modifiers

using System; 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,                 CallingConventions.HasThis, types, null);             if(constructorInfoObj != null)             {                 Console.WriteLine("The constructor of MyClass1 that is a public " +                     "instance method and takes an integer as a parameter is: ");                 Console.WriteLine(constructorInfoObj.ToString());             }             else             {                 Console.WriteLine("The constructor of MyClass1 that is a public instance " +                     "method and takes an integer as a parameter is not available.");             }     } }