Ver Mensaje Individual
  #6 (permalink)  
Antiguo 08/01/2007, 09:07
Guitar
 
Fecha de Ingreso: marzo-2004
Ubicación: hell
Mensajes: 35
Antigüedad: 20 años, 2 meses
Puntos: 0
Re: Llamar a un metodo sin saber el nombre

Cita:
Iniciado por xknown Ver Mensaje
Estimado, lee la documentación -por eso dejé el filtro de búsqueda.
Ya me la había leído, pero tengo dudas sobre su utilización y preguntaba por si me poníais un ejemplo real.

Para enviarme al google o MSDN no necesito tu ayuda.

Por si alguien está en la misma situación que yo, pego aquí el código que estoy utilizando.

public void Test()
{
MyClass myClass = new MyClass();
MyInterface myInterface = (MyInterface)myClass;
MyDoSomethingArgs myArgs = new MyDoSomethingArgs();
TestMethod(myClass, "DoSomething", myArgs);
TestMethod(myInterface, "DoSomething", myArgs);
}
public void TestMethod(object target, string method, params object[] args)
{
// Do a ton of setup
target.GetType().InvokeMember(method,
System.Reflection.BindingFlags.InvokeMethod, null,
target, args);
// Analyze the results and tear it all down
}

Saludos y gracias,

Guitar