using System;
using System.Reflection;
namespace Recetas.Cap03
{
public class Calculadora
{
public virtual int Sumar(int a, int b)
{
return a + b;
}
}
public class Aplicacion
{
public static void Main()
{
Console.WriteLine("\nReflection: MethodInfo");
// Crea un objeto de `Calculadora`:
Calculadora calc = new Calculadora();
// Obtención de la información del tipo:
Type infoTipo = calc.GetType();
// Información de método:
MethodInfo infoMetodo = infoTipo.GetMethod("Sumar");
// Argumentos del método `Sumar`:
object[] args = new object[] {3, 7};
// Invocación del método:
Console.WriteLine("Nombre tipo: {0}\n\tRetorno: {1}\n", infoTipo.FullName, infoMetodo.Invoke(calc, args));
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uUmVmbGVjdGlvbjsKCm5hbWVzcGFjZSBSZWNldGFzLkNhcDAzCnsKICAgIHB1YmxpYyBjbGFzcyBDYWxjdWxhZG9yYQogICAgewogICAgICAgIHB1YmxpYyB2aXJ0dWFsIGludCBTdW1hcihpbnQgYSwgaW50IGIpCiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gYSArIGI7CiAgICAgICAgfQogICAgfQogICAgCiAgICBwdWJsaWMgY2xhc3MgQXBsaWNhY2lvbgogICAgewogICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgICAgICB7CiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCJcblJlZmxlY3Rpb246IE1ldGhvZEluZm8iKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIENyZWEgdW4gb2JqZXRvIGRlIGBDYWxjdWxhZG9yYWA6CiAgICAgICAgICAgIENhbGN1bGFkb3JhIGNhbGMgPSBuZXcgQ2FsY3VsYWRvcmEoKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIE9idGVuY2nDs24gZGUgbGEgaW5mb3JtYWNpw7NuIGRlbCB0aXBvOgogICAgICAgICAgICBUeXBlIGluZm9UaXBvID0gY2FsYy5HZXRUeXBlKCk7CiAgICAgICAgICAgIAogICAgICAgICAgICAvLyBJbmZvcm1hY2nDs24gZGUgbcOpdG9kbzoKICAgICAgICAgICAgTWV0aG9kSW5mbyBpbmZvTWV0b2RvID0gaW5mb1RpcG8uR2V0TWV0aG9kKCJTdW1hciIpOwogICAgICAgICAgICAKICAgICAgICAgICAgLy8gQXJndW1lbnRvcyBkZWwgbcOpdG9kbyBgU3VtYXJgOgogICAgICAgICAgICBvYmplY3RbXSBhcmdzID0gbmV3IG9iamVjdFtdIHszLCA3fTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIEludm9jYWNpw7NuIGRlbCBtw6l0b2RvOgogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiTm9tYnJlIHRpcG86IHswfVxuXHRSZXRvcm5vOiB7MX1cbiIsIGluZm9UaXBvLkZ1bGxOYW1lLCBpbmZvTWV0b2RvLkludm9rZShjYWxjLCBhcmdzKSk7CiAgICAgICAgfQogICAgfQp9