Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Last active August 29, 2015 14:02
Show Gist options
  • Save Fhernd/d49e957bd8f5a5d990a9 to your computer and use it in GitHub Desktop.
Save Fhernd/d49e957bd8f5a5d990a9 to your computer and use it in GitHub Desktop.
Demostración del uso del método GetMethod(string, Type[]) en C#.
using System;
using System.Reflection;
namespace Recetas.Cap03
{
internal class UsoGetMethodInfo
{
public void MetodoA(int i, int j) { }
public void MetodoA(int[] i) { }
public unsafe void MetodoA(int* i) { }
public void MetodoA(ref int r) { }
public void MetodoA( int i, out int o)
{
o = 101;
}
public static void Main()
{
MethodInfo infoMetodo;
// Búsqueda del método con la firma MetodoA(int i, int j):
infoMetodo = typeof(UsoGetMethodInfo).GetMethod("MetodoA",
new Type[] {typeof(int), typeof(int) });
Console.WriteLine("\nNombre completo método: {0}", infoMetodo);
// Búsqueda del método con la firma Metodo(int[]):
infoMetodo = typeof(UsoGetMethodInfo).GetMethod("MetodoA",
new Type[] {typeof(int[])});
Console.WriteLine("\nNombre completo método: {0}", infoMetodo);
// Búsqueda método con la firma MetodoA(int*):
infoMetodo = typeof(UsoGetMethodInfo).GetMethod("MetodoA",
new Type[] { typeof(int).MakePointerType()});
Console.WriteLine("\nNombre completo método: {0}", infoMetodo);
// Búsqueda método con la firma MetodoA(ref int):
infoMetodo = typeof(UsoGetMethodInfo).GetMethod("MetodoA",
new Type[] {typeof(int).MakeByRefType()});
Console.WriteLine("\nNombre completo método: {0}", infoMetodo);
// Búsqueda método con la firma MetodoA(int, out int):
infoMetodo = typeof(UsoGetMethodInfo).GetMethod("MetodoA",
new Type[] {typeof(int), typeof(int).MakeByRefType()});
Console.WriteLine("\nNombre completo método: {0}\n", infoMetodo);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment