public sealed override object Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { #if ENABLE_REFLECTION_TRACE if (ReflectionTrace.Enabled) { ReflectionTrace.ConstructorInfo_Invoke(this, parameters); } #endif if (invokeAttr != BindingFlags.Default || binder != null || culture != null) { throw new NotImplementedException(); } if (parameters == null) { parameters = Array.Empty <Object>(); } // Most objects are allocated by NewObject and their constructors return "void". But in many frameworks, // there are "weird" cases (e.g. String) where the constructor must do both the allocation and initialization. // Reflection.Core does not hardcode these special cases. It's up to the ExecutionEnvironment to steer // us the right way by coordinating the implementation of NewObject and MethodInvoker. Object newObject = ReflectionCoreExecution.ExecutionEnvironment.NewObject(this.DeclaringType.TypeHandle); Object ctorAllocatedObject = this.MethodInvoker.Invoke(newObject, parameters); return(newObject != null ? newObject : ctorAllocatedObject); }
public sealed override Object Invoke(Object[] parameters) { if (ReflectionTrace.Enabled) { ReflectionTrace.ConstructorInfo_Invoke(this, parameters); } if (parameters == null) { parameters = Array.Empty <Object>(); } // Most objects are allocated by NewObject and their constructors return "void". But in many frameworks, // there are "weird" cases (e.g. String) where the constructor must do both the allocation and initialization. // Reflection.Core does not hardcode these special cases. It's up to the ExecutionEnvironment to steer // us the right way by coordinating the implementation of NewObject and MethodInvoker. Object newObject = ReflectionCoreExecution.ExecutionEnvironment.NewObject(this.DeclaringType.TypeHandle); Object ctorAllocatedObject = this.MethodInvoker.Invoke(newObject, parameters); return(newObject != null ? newObject : ctorAllocatedObject); }