Advertisement
Fhernd

UsoTypeGetConstructor.cs

Aug 16th, 2014
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  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.                     Console.WriteLine ("Constructor con firma que contiene un parámetro `int`: {0}",
  23.                                        constructor.ToString());
  24.                 }
  25.                 else
  26.                 {
  27.                     Console.WriteLine("No se encontré ningún constructor con la firma especificada.\n");
  28.                 }
  29.             }
  30.             catch (Exception e)
  31.             {
  32.                 // Area de tratamiento de la excepción.
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement