I want to write this in C#:
SomeUnknownType x;
SuperDuperInvoke(x, "MethodName", param1, param2, param3);
SuperDuperInvoke2(x, "MethodName", "param1String", "param2String", "param3String");
Get some object I know nothing about, a method name, and a list of parameters, and just call the method. SuperDuperInvoke2 assumes the parameters are convertible from string.
I assume something like this is possible using the dynamic framework… I just can’t find how…
I know I can do this with Reflection, but it’s ugly and annoying…
I’ll explain myself a little.
I want to use this for integration testing of some business server.
The server has a lot of different components that can handle requests, all loaded into an IoC container.
I need to expose some of thees components, mostly for testing, so I want to just receive the name of the component, what method i should call with what parameters and just call it.
I know you wrote that you don’t like Reflection but is this really all that ugly?
If the method could be overloaded you can’t go by name only but also need to know how many parameters you are going to invoke it with. Something like this
This will not work if you also need to match your methodParams by type.