Mega Code Archive

 
Categories / C# / Reflection
 

ConstructorInfo Class Discovers the attributes of a class constructor

using System; using System.Reflection; using System.Security; public class MyClass1 {     public MyClass1(int i){}     public static void Main()     {         try         {             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(constructorInfoObj.ToString());             }         }         catch(ArgumentNullException e)         {             Console.WriteLine("ArgumentNullException: " + e.Message);         }         catch(ArgumentException e)         {             Console.WriteLine("ArgumentException: " + e.Message);         }         catch(SecurityException e)         {             Console.WriteLine("SecurityException: " + e.Message);         }         catch(Exception e)         {             Console.WriteLine("Exception: " + e.Message);         }     } }