using System;
using System.Reflection;
namespace Recetas.Cap03
{
public sealed class ReflectionConInvokeMethod
{
public static void ImprimirMensaje(string param1, int param2, char param3)
{
Console.WriteLine ("\nValores de `param1`: {0}; `param2`: {1}; `param3`: {2}\n",
param1, param2.ToString(), param3.ToString());
}
public static void Main()
{
// Creación objeto de `ReflectionConInvokeMethod`:
object objeto = new ReflectionConInvokeMethod();
// Obtención de representación `Type` de `ReflectionConInvokeMethod`:
Type tipo = typeof(ReflectionConInvokeMethod);
// Obtiene representación `MethodInfo` con el nombre
// y parámetros especificados en los argumentos de `GetMethod`:
MethodInfo infoMetodo = tipo.GetMethod ("ImprimirMensaje",
new Type[] { typeof(string), typeof(int), typeof(char) }
);
// Invoca el método con los argumentos espeificados en `InvokeMember`:
tipo.InvokeMember ("ImprimirMensaje", BindingFlags.InvokeMethod,
null, objeto, new Object[] { "Blog xCSw", 235, '#'}
);
// Uso de `Invoke` de `MethodInfo` para invocar el
// método `ImprimirMensaje`:
infoMetodo.Invoke( null, BindingFlags.InvokeMethod,
null, new Object[] { "Blog xCSw", 235, '#'}, null
);
}
}
}