I'm trying to handle a call of a generic method through a RealProxy, but I cannot seem to find the information about the actual type of the generic parameter used in the intercepted method call. An excerpt of the code:
public override IMessage Invoke(IMessage msg)
{
...
string methodName = (string)msg.Properties["__MethodName"];
Type[] parameterTypes = (Type[])msg.Properties["__MethodSignature"];
object[] args = (object[])msg.Properties["__Args"];
MethodInfo method = typeToProxy.GetMethod(methodName, parameterTypes);
...
Let's say I'm proxying an interface like
interface IFactory
{
TService Create<TService>()
}
When I call the proxy
proxied.Create<MyClass>()
I want to be able to find out the generic parameter is of type MyClass. Is this possible through RealProxy?
There is an excellent MSDN article about RealProxy which I recommend you read. Among other things, it introduces
MethodCallMessageWrapperwhich saves you the trouble of working directly against thePropertiesdictionary. From the latter you can get theMethodBase, which in turn contains the generic arguments: