As you say, โI donโt know the return type or the parameters in advance,โ I think Dynamic Proxy is what you need.
Unfortunately, I only know about dynamic proxies in Java. But I'm sure there is something similar for C #.
Try Google's โDynamic C # Proxyโ.
For example, for C # there is an implementation: http://www.castleproject.org/dynamicproxy/
So what is a dynamic proxy?
From the JavaDoc http://docs.oracle.com/javase/1.3/docs/guide/reflection/proxy.html#api :
A dynamic proxy class is a class that implements a list of interfaces specified at runtime , so a method call through one of the interfaces in the class instance will be encoded and sent to another object through a uniform interface. Thus, a dynamic proxy class can be used to create a protected type of proxy object for a list of interfaces without requiring a preliminary generation of a proxy class, for example, with compilation time tools. Method calls for an instance of a dynamic proxy class are sent to the only method in the instance call handler , and they are encoded using the java.lang.reflect.Method object that defines the method that was called and an array of type Object containing the arguments.
source share