public sealed override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { #if ENABLE_REFLECTION_TRACE if (ReflectionTrace.Enabled) { ReflectionTrace.MethodBase_Invoke(this, obj, parameters); } #endif if (parameters == null) { parameters = Array.Empty <Object>(); } MethodInvoker methodInvoker = this.MethodInvoker; object result = methodInvoker.Invoke(obj, parameters, binder, invokeAttr, culture); System.Diagnostics.DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); return(result); }
public sealed override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { #if ENABLE_REFLECTION_TRACE if (ReflectionTrace.Enabled) { ReflectionTrace.MethodBase_Invoke(this, obj, parameters); } #endif if (parameters == null) { parameters = Array.Empty <Object>(); } MethodInvoker methodInvoker; try { methodInvoker = this.MethodInvoker; } catch (Exception) { // // Project N compat note: On the desktop, ConstructorInfo.Invoke(Object[]) specifically forbids invoking static constructors (and // for us, that check is embedded inside the MethodInvoker property call.) Howver, MethodBase.Invoke(Object, Object[]) allows it. This was // probably an oversight on the desktop. We choose not to support this loophole on Project N for the following reasons: // // 1. The Project N toolchain aggressively replaces static constructors with static initialization data whenever possible. // So the static constructor may no longer exist. // // 2. Invoking the static constructor through Reflection is not very useful as it invokes the static constructor whether or not // it was already run. Since static constructors are specifically one-shot deals, this will almost certainly mess up the // type's internal assumptions. // if (this.IsStatic) { throw new PlatformNotSupportedException(SR.Acc_NotClassInit); } throw; } object result = methodInvoker.Invoke(obj, parameters, binder, invokeAttr, culture); System.Diagnostics.DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); return(result); }