Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Reflection;
  3.  
  4. namespace Recetas.Cap03
  5. {
  6.     public class UsoTypeGetConstructor
  7.     {
  8.         public UsoTypeGetConstructor() { }
  9.         public UsoTypeGetConstructor(int i) { }
  10.        
  11.         public static void Main()
  12.         {
  13.             try
  14.             {
  15.                 Type tipo = typeof (UsoTypeGetConstructor);
  16.                
  17.                 // Aquí obtiene el constructor con parámetro entero (int):
  18.                 ConstructorInfo constructor = tipo.GetConstructor(new Type[] {typeof(int)});
  19.                
  20.                 if (constructor != null)
  21.                 {
  22.                     UsoTypeGetConstructor obj = (UsoTypeGetConstructor) constructor.Invoke( new object[] {13});
  23.                    
  24.                     obj.MostrarMensaje();
  25.                 }
  26.                 else
  27.                 {
  28.                     Console.WriteLine("No se encontré ningún constructor con la firma especificada.\n");
  29.                 }
  30.             }
  31.             catch (Exception e)
  32.             {
  33.                 // Area de tratamiento de la excepción.
  34.             }
  35.         }
  36.        
  37.         public void MostrarMensaje()
  38.         {
  39.             Console.WriteLine ("Blog xCSw");
  40.         }
  41.     }
  42. }