3 // Copyright(c) Microsoft Corporation. All rights reserved.
6 // <OWNER>Microsoft</OWNER>
9 namespace System.Reflection
12 using System.Collections.Generic;
13 using System.Diagnostics;
14 using System.Diagnostics.Contracts;
15 using System.Globalization;
17 using System.Runtime.ConstrainedExecution;
18 using System.Runtime.InteropServices;
20 using System.Runtime.Remoting.Metadata;
21 #endif //FEATURE_REMOTING
22 using System.Runtime.Serialization;
23 using System.Security;
24 using System.Security.Permissions;
25 using System.Threading;
26 using MemberListType = System.RuntimeType.MemberListType;
27 using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache;
28 using System.Runtime.CompilerServices;
31 [ClassInterface(ClassInterfaceType.None)]
32 [ComDefaultInterface(typeof(_ConstructorInfo))]
33 #pragma warning disable 618
34 [PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
35 #pragma warning restore 618
36 [System.Runtime.InteropServices.ComVisible(true)]
37 public abstract class ConstructorInfo : MethodBase, _ConstructorInfo
39 #region Static Members
40 [System.Runtime.InteropServices.ComVisible(true)]
41 public readonly static String ConstructorName = ".ctor";
43 [System.Runtime.InteropServices.ComVisible(true)]
44 public readonly static String TypeConstructorName = ".cctor";
48 protected ConstructorInfo() { }
52 public static bool operator ==(ConstructorInfo left, ConstructorInfo right)
54 if (ReferenceEquals(left, right))
57 if ((object)left == null || (object)right == null ||
58 left is RuntimeConstructorInfo || right is RuntimeConstructorInfo)
62 return left.Equals(right);
65 public static bool operator !=(ConstructorInfo left, ConstructorInfo right)
67 return !(left == right);
69 #endif // !FEATURE_CORECLR
71 public override bool Equals(object obj)
73 return base.Equals(obj);
76 public override int GetHashCode()
78 return base.GetHashCode();
81 #region Internal Members
82 internal virtual Type GetReturnType() { throw new NotImplementedException(); }
85 #region MemberInfo Overrides
86 [System.Runtime.InteropServices.ComVisible(true)]
87 public override MemberTypes MemberType { get { return System.Reflection.MemberTypes.Constructor; } }
90 #region Public Abstract\Virtual Members
91 public abstract Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
94 #region Public Members
95 [DebuggerStepThroughAttribute]
96 [Diagnostics.DebuggerHidden]
97 public Object Invoke(Object[] parameters)
99 // Theoretically we should set up a LookForMyCaller stack mark here and pass that along.
100 // But to maintain backward compatibility we can't switch to calling an
101 // internal overload that takes a stack mark.
102 // Fortunately the stack walker skips all the reflection invocation frames including this one.
103 // So this method will never be returned by the stack walker as the caller.
104 // See SystemDomain::CallersMethodCallbackWithStackMark in AppDomain.cpp.
105 return Invoke(BindingFlags.Default, null, parameters, null);
110 #region COM Interop Support
111 Type _ConstructorInfo.GetType()
113 return base.GetType();
116 Object _ConstructorInfo.Invoke_2(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
118 return Invoke(obj, invokeAttr, binder, parameters, culture);
121 Object _ConstructorInfo.Invoke_3(Object obj, Object[] parameters)
123 return Invoke(obj, parameters);
126 Object _ConstructorInfo.Invoke_4(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
128 return Invoke(invokeAttr, binder, parameters, culture);
131 Object _ConstructorInfo.Invoke_5(Object[] parameters)
133 return Invoke(parameters);
136 void _ConstructorInfo.GetTypeInfoCount(out uint pcTInfo)
138 throw new NotImplementedException();
141 void _ConstructorInfo.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
143 throw new NotImplementedException();
146 void _ConstructorInfo.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
148 throw new NotImplementedException();
151 // If you implement this method, make sure to include _ConstructorInfo.Invoke in VM\DangerousAPIs.h and
152 // include _ConstructorInfo in SystemDomain::IsReflectionInvocationMethod in AppDomain.cpp.
153 void _ConstructorInfo.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
155 throw new NotImplementedException();
162 internal sealed class RuntimeConstructorInfo : ConstructorInfo, ISerializable, IRuntimeMethodInfo
164 #region Private Data Members
165 private volatile RuntimeType m_declaringType;
166 private RuntimeTypeCache m_reflectedTypeCache;
167 private string m_toString;
168 private ParameterInfo[] m_parameters = null; // Created lazily when GetParameters() is called.
169 #pragma warning disable 169
170 private object _empty1; // These empties are used to ensure that RuntimeConstructorInfo and RuntimeMethodInfo are have a layout which is sufficiently similar
171 private object _empty2;
172 private object _empty3;
173 #pragma warning restore 169
174 private IntPtr m_handle;
175 private MethodAttributes m_methodAttributes;
176 private BindingFlags m_bindingFlags;
177 private volatile Signature m_signature;
178 private INVOCATION_FLAGS m_invocationFlags;
181 private bool IsNonW8PFrameworkAPI()
183 if (DeclaringType.IsArray && IsPublic && !IsStatic)
186 RuntimeAssembly rtAssembly = GetRuntimeAssembly();
187 if (rtAssembly.IsFrameworkAssembly())
189 int ctorToken = rtAssembly.InvocableAttributeCtorToken;
190 if (System.Reflection.MetadataToken.IsNullToken(ctorToken) ||
191 !CustomAttribute.IsAttributeDefined(GetRuntimeModule(), MetadataToken, ctorToken))
195 if (GetRuntimeType().IsNonW8PFrameworkAPI())
201 internal override bool IsDynamicallyInvokable
205 return !AppDomain.ProfileAPICheck || !IsNonW8PFrameworkAPI();
208 #endif // FEATURE_APPX
210 internal INVOCATION_FLAGS InvocationFlags
212 [System.Security.SecuritySafeCritical]
215 if ((m_invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED) == 0)
217 INVOCATION_FLAGS invocationFlags = INVOCATION_FLAGS.INVOCATION_FLAGS_IS_CTOR; // this is a given
219 Type declaringType = DeclaringType;
222 // first take care of all the NO_INVOKE cases.
223 if ( declaringType == typeof(void) ||
224 (declaringType != null && declaringType.ContainsGenericParameters) ||
225 ((CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs) ||
226 ((Attributes & MethodAttributes.RequireSecObject) == MethodAttributes.RequireSecObject))
228 // We don't need other flags if this method cannot be invoked
229 invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE;
231 else if (IsStatic || declaringType != null && declaringType.IsAbstract)
233 invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NO_CTOR_INVOKE;
237 // this should be an invocable method, determine the other flags that participate in invocation
238 invocationFlags |= RuntimeMethodHandle.GetSecurityFlags(this);
240 if ( (invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) == 0 &&
241 ((Attributes & MethodAttributes.MemberAccessMask) != MethodAttributes.Public ||
242 (declaringType != null && declaringType.NeedsReflectionSecurityCheck)) )
244 // If method is non-public, or declaring type is not visible
245 invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY;
248 // Check for attempt to create a delegate class, we demand unmanaged
249 // code permission for this since it's hard to validate the target address.
250 if (typeof(Delegate).IsAssignableFrom(DeclaringType))
251 invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR;
255 if (AppDomain.ProfileAPICheck && IsNonW8PFrameworkAPI())
256 invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API;
257 #endif // FEATURE_APPX
259 m_invocationFlags = invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED;
262 return m_invocationFlags;
268 [System.Security.SecurityCritical] // auto-generated
269 internal RuntimeConstructorInfo(
270 RuntimeMethodHandleInternal handle, RuntimeType declaringType, RuntimeTypeCache reflectedTypeCache,
271 MethodAttributes methodAttributes, BindingFlags bindingFlags)
273 Contract.Ensures(methodAttributes == RuntimeMethodHandle.GetAttributes(handle));
275 m_bindingFlags = bindingFlags;
276 m_reflectedTypeCache = reflectedTypeCache;
277 m_declaringType = declaringType;
278 m_handle = handle.Value;
279 m_methodAttributes = methodAttributes;
284 #region Legacy Remoting Cache
285 // The size of CachedData is accounted for by BaseObjectWithCachedData in object.h.
286 // This member is currently being used by Remoting for caching remoting data. If you
287 // need to cache data here, talk to the Remoting team to work out a mechanism, so that
288 // both caching systems can happily work together.
289 private RemotingMethodCachedData m_cachedData;
291 internal RemotingMethodCachedData RemotingCache
295 // This grabs an internal copy of m_cachedData and uses
296 // that instead of looking at m_cachedData directly because
297 // the cache may get cleared asynchronously. This prevents
298 // us from having to take a lock.
299 RemotingMethodCachedData cache = m_cachedData;
302 cache = new RemotingMethodCachedData(this);
303 RemotingMethodCachedData ret = Interlocked.CompareExchange(ref m_cachedData, cache, null);
311 #endif //FEATURE_REMOTING
313 #region NonPublic Methods
314 RuntimeMethodHandleInternal IRuntimeMethodInfo.Value
316 [System.Security.SecuritySafeCritical]
319 return new RuntimeMethodHandleInternal(m_handle);
323 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
324 internal override bool CacheEquals(object o)
326 RuntimeConstructorInfo m = o as RuntimeConstructorInfo;
328 if ((object)m == null)
331 return m.m_handle == m_handle;
334 private Signature Signature
338 if (m_signature == null)
339 m_signature = new Signature(this, m_declaringType);
345 private RuntimeType ReflectedTypeInternal
349 return m_reflectedTypeCache.GetRuntimeType();
353 private void CheckConsistency(Object target)
355 if (target == null && IsStatic)
358 if (!m_declaringType.IsInstanceOfType(target))
361 throw new TargetException(Environment.GetResourceString("RFLCT.Targ_StatMethReqTarg"));
363 throw new TargetException(Environment.GetResourceString("RFLCT.Targ_ITargMismatch"));
367 internal BindingFlags BindingFlags { get { return m_bindingFlags; } }
369 // Differs from MethodHandle in that it will return a valid handle even for reflection only loaded types
370 internal RuntimeMethodHandle GetMethodHandle()
372 return new RuntimeMethodHandle(this);
375 internal bool IsOverloaded
379 return m_reflectedTypeCache.GetConstructorList(MemberListType.CaseSensitive, Name).Length > 1;
384 #region Object Overrides
385 public override String ToString()
387 // "Void" really doesn't make sense here. But we'll keep it for compat reasons.
388 if (m_toString == null)
389 m_toString = "Void " + FormatNameAndSig();
395 #region ICustomAttributeProvider
396 public override Object[] GetCustomAttributes(bool inherit)
398 return CustomAttribute.GetCustomAttributes(this, typeof(object) as RuntimeType);
401 public override Object[] GetCustomAttributes(Type attributeType, bool inherit)
403 if (attributeType == null)
404 throw new ArgumentNullException("attributeType");
405 Contract.EndContractBlock();
407 RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType;
409 if (attributeRuntimeType == null)
410 throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType");
412 return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType);
415 [System.Security.SecuritySafeCritical] // auto-generated
416 public override bool IsDefined(Type attributeType, bool inherit)
418 if (attributeType == null)
419 throw new ArgumentNullException("attributeType");
420 Contract.EndContractBlock();
422 RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType;
424 if (attributeRuntimeType == null)
425 throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType");
427 return CustomAttribute.IsDefined(this, attributeRuntimeType);
430 public override IList<CustomAttributeData> GetCustomAttributesData()
432 return CustomAttributeData.GetCustomAttributesInternal(this);
437 #region MemberInfo Overrides
438 public override String Name
440 [System.Security.SecuritySafeCritical] // auto-generated
441 get { return RuntimeMethodHandle.GetName(this); }
443 [System.Runtime.InteropServices.ComVisible(true)]
444 public override MemberTypes MemberType { get { return MemberTypes.Constructor; } }
446 public override Type DeclaringType
450 return m_reflectedTypeCache.IsGlobal ? null : m_declaringType;
454 public override Type ReflectedType
458 return m_reflectedTypeCache.IsGlobal ? null : ReflectedTypeInternal;
462 public override int MetadataToken
464 [System.Security.SecuritySafeCritical] // auto-generated
465 get { return RuntimeMethodHandle.GetMethodDef(this); }
467 public override Module Module
469 get { return GetRuntimeModule(); }
472 internal RuntimeType GetRuntimeType() { return m_declaringType; }
473 internal RuntimeModule GetRuntimeModule() { return RuntimeTypeHandle.GetModule(m_declaringType); }
474 internal RuntimeAssembly GetRuntimeAssembly() { return GetRuntimeModule().GetRuntimeAssembly(); }
477 #region MethodBase Overrides
479 // This seems to always returns System.Void.
480 internal override Type GetReturnType() { return Signature.ReturnType; }
482 [System.Security.SecuritySafeCritical] // auto-generated
483 internal override ParameterInfo[] GetParametersNoCopy()
485 if (m_parameters == null)
486 m_parameters = RuntimeParameterInfo.GetParameters(this, this, Signature);
492 public override ParameterInfo[] GetParameters()
494 ParameterInfo[] parameters = GetParametersNoCopy();
496 if (parameters.Length == 0)
499 ParameterInfo[] ret = new ParameterInfo[parameters.Length];
500 Array.Copy(parameters, ret, parameters.Length);
504 public override MethodImplAttributes GetMethodImplementationFlags()
506 return RuntimeMethodHandle.GetImplAttributes(this);
509 public override RuntimeMethodHandle MethodHandle
513 Type declaringType = DeclaringType;
514 if ((declaringType == null && Module.Assembly.ReflectionOnly) || declaringType is ReflectionOnlyType)
515 throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAllowedInReflectionOnly"));
516 return new RuntimeMethodHandle(this);
520 public override MethodAttributes Attributes
524 return m_methodAttributes;
528 public override CallingConventions CallingConvention
532 return Signature.CallingConvention;
536 internal static void CheckCanCreateInstance(Type declaringType, bool isVarArg)
538 if (declaringType == null)
539 throw new ArgumentNullException("declaringType");
540 Contract.EndContractBlock();
542 // ctor is ReflectOnly
543 if (declaringType is ReflectionOnlyType)
544 throw new InvalidOperationException(Environment.GetResourceString("Arg_ReflectionOnlyInvoke"));
546 // ctor is declared on interface class
547 else if (declaringType.IsInterface)
548 throw new MemberAccessException(
549 String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Acc_CreateInterfaceEx"), declaringType));
551 // ctor is on an abstract class
552 else if (declaringType.IsAbstract)
553 throw new MemberAccessException(
554 String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Acc_CreateAbstEx"), declaringType));
556 // ctor is on a class that contains stack pointers
557 else if (declaringType.GetRootElementType() == typeof(ArgIterator))
558 throw new NotSupportedException();
562 throw new NotSupportedException();
564 // ctor is generic or on a generic class
565 else if (declaringType.ContainsGenericParameters)
567 #if FEATURE_LEGACYNETCF
568 if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
569 throw new ArgumentException(
570 String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Acc_CreateGenericEx"), declaringType));
573 throw new MemberAccessException(
574 String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Acc_CreateGenericEx"), declaringType));
577 // ctor is declared on System.Void
578 else if (declaringType == typeof(void))
579 throw new MemberAccessException(Environment.GetResourceString("Access_Void"));
582 internal void ThrowNoInvokeException()
584 CheckCanCreateInstance(DeclaringType, (CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs);
587 if ((Attributes & MethodAttributes.Static) == MethodAttributes.Static)
588 throw new MemberAccessException(Environment.GetResourceString("Acc_NotClassInit"));
590 throw new TargetException();
593 [System.Security.SecuritySafeCritical] // auto-generated
594 [DebuggerStepThroughAttribute]
595 [Diagnostics.DebuggerHidden]
596 [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
597 public override Object Invoke(
598 Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
600 INVOCATION_FLAGS invocationFlags = InvocationFlags;
602 if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE) != 0)
603 ThrowNoInvokeException();
605 // check basic method consistency. This call will throw if there are problems in the target/method relationship
606 CheckConsistency(obj);
609 if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
611 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
612 RuntimeAssembly caller = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
613 if (caller != null && !caller.IsSafeForReflection())
614 throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", FullName));
622 // For unverifiable code, we require the caller to be critical.
623 // Adding the INVOCATION_FLAGS_NEED_SECURITY flag makes that check happen
624 invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY;
625 #else // FEATURE_CORECLR
626 new SecurityPermission(SecurityPermissionFlag.SkipVerification).Demand();
627 #endif // FEATURE_CORECLR
631 if ((invocationFlags &(INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY)) != 0)
634 if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD) != 0)
635 CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
636 if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != 0)
637 #endif // !FEATURE_CORECLR
638 RuntimeMethodHandle.PerformSecurityCheck(obj, this, m_declaringType, (uint)m_invocationFlags);
641 Signature sig = Signature;
644 int formalCount = sig.Arguments.Length;
645 int actualCount =(parameters != null) ? parameters.Length : 0;
646 if (formalCount != actualCount)
647 throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
649 // if we are here we passed all the previous checks. Time to look at the arguments
652 Object[] arguments = CheckArguments(parameters, binder, invokeAttr, culture, sig);
653 Object retValue = RuntimeMethodHandle.InvokeMethod(obj, arguments, sig, false);
654 // copy out. This should be made only if ByRef are present.
655 for (int index = 0; index < arguments.Length; index++)
656 parameters[index] = arguments[index];
659 return RuntimeMethodHandle.InvokeMethod(obj, null, sig, false);
663 [System.Security.SecuritySafeCritical] // overrides SC member
664 #pragma warning disable 618
665 [ReflectionPermissionAttribute(SecurityAction.Demand, Flags = ReflectionPermissionFlag.MemberAccess)]
666 #pragma warning restore 618
667 public override MethodBody GetMethodBody()
669 MethodBody mb = RuntimeMethodHandle.GetMethodBody(this, ReflectedTypeInternal);
671 mb.m_methodBase = this;
675 public override bool IsSecurityCritical
677 get { return RuntimeMethodHandle.IsSecurityCritical(this); }
680 public override bool IsSecuritySafeCritical
682 get { return RuntimeMethodHandle.IsSecuritySafeCritical(this); }
685 public override bool IsSecurityTransparent
687 get { return RuntimeMethodHandle.IsSecurityTransparent(this); }
690 public override bool ContainsGenericParameters
694 return (DeclaringType != null && DeclaringType.ContainsGenericParameters);
699 #region ConstructorInfo Overrides
700 [System.Security.SecuritySafeCritical] // auto-generated
701 [DebuggerStepThroughAttribute]
702 [Diagnostics.DebuggerHidden]
703 [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
704 public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
706 INVOCATION_FLAGS invocationFlags = InvocationFlags;
708 // get the declaring TypeHandle early for consistent exceptions in IntrospectionOnly context
709 RuntimeTypeHandle declaringTypeHandle = m_declaringType.TypeHandle;
711 if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE | INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS | INVOCATION_FLAGS.INVOCATION_FLAGS_NO_CTOR_INVOKE)) != 0)
712 ThrowNoInvokeException();
715 if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
717 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
718 RuntimeAssembly caller = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
719 if (caller != null && !caller.IsSafeForReflection())
720 throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", FullName));
724 if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY | INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR)) != 0)
727 if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD) != 0)
728 CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
729 if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != 0)
730 #endif // !FEATURE_CORECLR
731 RuntimeMethodHandle.PerformSecurityCheck(null, this, m_declaringType, (uint)(m_invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_CONSTRUCTOR_INVOKE));
733 if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR) != 0)
734 new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
735 #endif // !FEATURE_CORECLR
739 Signature sig = Signature;
741 int formalCount = sig.Arguments.Length;
742 int actualCount =(parameters != null) ? parameters.Length : 0;
743 if (formalCount != actualCount)
744 throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
746 // We don't need to explicitly invoke the class constructor here,
747 // JIT/NGen will insert the call to .cctor in the instance ctor.
749 // if we are here we passed all the previous checks. Time to look at the arguments
752 Object[] arguments = CheckArguments(parameters, binder, invokeAttr, culture, sig);
753 Object retValue = RuntimeMethodHandle.InvokeMethod(null, arguments, sig, true);
754 // copy out. This should be made only if ByRef are present.
755 for (int index = 0; index < arguments.Length; index++)
756 parameters[index] = arguments[index];
759 return RuntimeMethodHandle.InvokeMethod(null, null, sig, true);
763 #region ISerializable Implementation
764 [System.Security.SecurityCritical] // auto-generated
765 public void GetObjectData(SerializationInfo info, StreamingContext context)
768 throw new ArgumentNullException("info");
769 Contract.EndContractBlock();
770 MemberInfoSerializationHolder.GetSerializationInfo(
773 ReflectedTypeInternal,
775 SerializationToString(),
776 MemberTypes.Constructor,
780 internal string SerializationToString()
782 // We don't need the return type for constructors.
783 return FormatNameAndSig(true);
786 internal void SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)
788 RuntimeMethodHandle.SerializationInvoke(this, target, info, ref context);