public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
// always ask for MemberAccess
new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
RuntimeMethodHandle method = m_owner.GetMethodDescriptor();
// ignore obj since it's a static method
if ((CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
throw new NotSupportedException(Environment.GetResourceString("NotSupported_CallToVarArg"));
// create a signature object
RuntimeTypeHandle[] argumentHandles = new RuntimeTypeHandle[m_owner.m_parameterTypes.Length];
for (int i = 0; i < argumentHandles.Length; i++)
argumentHandles[i] = m_owner.m_parameterTypes[i].TypeHandle;
Signature sig = new Signature(
method, argumentHandles, m_owner.m_returnType.TypeHandle, m_callingConvention);
// verify arguments
int formalCount = sig.Arguments.Length;
int actualCount = (parameters != null) ? parameters.Length : 0;
if (formalCount != actualCount)
throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
// if we are here we passed all the previous checks. Time to look at the arguments
Object retValue = null;
if (actualCount > 0) {
Object[] arguments = CheckArguments(parameters, binder, invokeAttr, culture, sig);
retValue = method.InvokeMethodFast(null, arguments, sig, m_attributes, RuntimeTypeHandle.EmptyHandle);
// copy out. This should be made only if ByRef are present.
for (int index = 0; index < actualCount; index++)
parameters[index] = arguments[index];
}
else {
retValue = method.InvokeMethodFast(null, null, sig, m_attributes, RuntimeTypeHandle.EmptyHandle);
}
GC.KeepAlive (this);
return retValue;
}