Created
June 6, 2014 21:48
-
-
Save Fhernd/721b104fd76ce17123bd to your computer and use it in GitHub Desktop.
Uso del método GetConstructor de la clase Type (System) en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
namespace Recetas.Cap03 | |
{ | |
public class UsoTypeGetConstructor | |
{ | |
public UsoTypeGetConstructor() { } | |
public UsoTypeGetConstructor(int i) { } | |
public static void Main() | |
{ | |
try | |
{ | |
Type tipo = typeof (UsoTypeGetConstructor); | |
// Aquí obtiene el constructor con parámetro entero (int): | |
ConstructorInfo constructor = tipo.GetConstructor(new Type[] {typeof(int)}); | |
if (constructor != null) | |
{ | |
Console.WriteLine ("Constructor con firma que contiene un parámetro `int`: {0}", | |
constructor.ToString()); | |
} | |
else | |
{ | |
Console.WriteLine("No se encontré ningún constructor con la firma especificada.\n"); | |
} | |
} | |
catch (Exception e) | |
{ | |
// Area de tratamiento de la excepción. | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment