private static MethodBase GetMethodBase(IMethodMessage msg, Type t, Type[] signature)
{
MethodBase mb = null;
// Get the reflection object depending on whether it is a
// constructor call or a method call.
if((msg is IConstructionCallMessage) ||
(msg is IConstructionReturnMessage))
{
if((null == signature))
{
BCLDebug.Trace("REMOTE", "RemotingServices.MethodBaseFromMethodCallMessage with null sig ", msg.MethodName);
ConstructorInfo[] ci;
RuntimeType rt = t as RuntimeType;
if (rt == null)
ci = t.GetConstructors();
else
ci = rt.GetConstructors();
if(1 != ci.Length)
{
// There is more than one constructor defined but
// we do not have a signature to differentiate between
// them.
throw new AmbiguousMatchException(
Environment.GetResourceString(
"Remoting_AmbiguousCTOR"));
}
mb = ci[0];
}
else
{
BCLDebug.Trace("REMOTE", "RemotingServices.MethodBaseFromMethodCallMessage with non-null sig ", msg.MethodName, " ", signature.Length);
RuntimeType rt = t as RuntimeType;
if (rt == null)
mb = t.GetConstructor(signature);
else
mb = rt.GetConstructor(signature);
}
}
else if((msg is IMethodCallMessage) || (msg is IMethodReturnMessage))
{
// We demand reflection permission in the api that calls this
// for non-public types
if(null == signature)
{
BCLDebug.Trace("REMOTE", "RemotingServices.MethodBaseFromMethodCallMessage with null sig ", msg.MethodName);
RuntimeType rt = t as RuntimeType;
if (rt == null)
mb = t.GetMethod(msg.MethodName, RemotingServices.LookupAll);
else
mb = rt.GetMethod(msg.MethodName, RemotingServices.LookupAll);
}
else
{
BCLDebug.Trace("REMOTE", "RemotingServices.MethodBaseFromMethodCallMessage with non-null sig ", msg.MethodName, " ", signature.Length);
RuntimeType rt = t as RuntimeType;
if (rt == null)
mb = t.GetMethod(msg.MethodName, RemotingServices.LookupAll, null, signature, null);
else
mb = rt.GetMethod(msg.MethodName, RemotingServices.LookupAll, null, CallingConventions.Any, signature, null);
}
}
return mb;
}