3 // Copyright(c) Microsoft Corporation. All rights reserved.
10 using System.Reflection;
11 using System.Reflection.Emit;
13 using System.Runtime.ConstrainedExecution;
14 using System.Diagnostics;
15 using System.Runtime.Serialization;
16 using System.Runtime.CompilerServices;
17 using System.Runtime.InteropServices;
18 using System.Threading;
19 using System.Runtime.Versioning;
21 using System.Globalization;
22 using System.Security;
23 using System.Security.Permissions;
24 using Microsoft.Win32.SafeHandles;
25 using System.Diagnostics.Contracts;
26 using StackCrawlMark = System.Threading.StackCrawlMark;
29 [System.Runtime.InteropServices.ComVisible(true)]
30 public unsafe struct RuntimeTypeHandle : ISerializable
32 // Returns handle for interop with EE. The handle is guaranteed to be non-null.
33 internal RuntimeTypeHandle GetNativeHandle()
35 // Create local copy to avoid ----s
36 RuntimeType type = m_type;
38 throw new ArgumentNullException(null, Environment.GetResourceString("Arg_InvalidHandle"));
39 return new RuntimeTypeHandle(type);
42 // Returns type for interop with EE. The type is guaranteed to be non-null.
43 internal RuntimeType GetTypeChecked()
45 // Create local copy to avoid ----s
46 RuntimeType type = m_type;
48 throw new ArgumentNullException(null, Environment.GetResourceString("Arg_InvalidHandle"));
52 [System.Security.SecurityCritical] // auto-generated
53 [ResourceExposure(ResourceScope.None)]
54 [MethodImplAttribute(MethodImplOptions.InternalCall)]
55 internal extern static bool IsInstanceOfType(RuntimeType type, Object o);
57 [System.Security.SecuritySafeCritical] // auto-generated
58 internal unsafe static Type GetTypeHelper(Type typeStart, Type[] genericArgs, IntPtr pModifiers, int cModifiers)
60 Type type = typeStart;
62 if (genericArgs != null)
64 type = type.MakeGenericType(genericArgs);
69 int* arModifiers = (int*)pModifiers.ToPointer();
70 for(int i = 0; i < cModifiers; i++)
72 if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.Ptr)
73 type = type.MakePointerType();
75 else if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.ByRef)
76 type = type.MakeByRefType();
78 else if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.SzArray)
79 type = type.MakeArrayType();
82 type = type.MakeArrayType(Marshal.ReadInt32((IntPtr)arModifiers, ++i * sizeof(int)));
89 public static bool operator ==(RuntimeTypeHandle left, object right) { return left.Equals(right); }
91 public static bool operator ==(object left, RuntimeTypeHandle right) { return right.Equals(left); }
93 public static bool operator !=(RuntimeTypeHandle left, object right) { return !left.Equals(right); }
95 public static bool operator !=(object left, RuntimeTypeHandle right) { return !right.Equals(left); }
97 internal static RuntimeTypeHandle EmptyHandle
101 return new RuntimeTypeHandle(null);
106 // This is the RuntimeType for the type
107 private RuntimeType m_type;
109 public override int GetHashCode()
111 return m_type != null ? m_type.GetHashCode() : 0;
114 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
115 public override bool Equals(object obj)
117 if(!(obj is RuntimeTypeHandle))
120 RuntimeTypeHandle handle =(RuntimeTypeHandle)obj;
121 return handle.m_type == m_type;
124 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
125 public bool Equals(RuntimeTypeHandle handle)
127 return handle.m_type == m_type;
132 #if !FEATURE_LEGACYNETCF
137 return m_type != null ? m_type.m_handle : IntPtr.Zero;
141 [System.Security.SecuritySafeCritical] // auto-generated
142 [ResourceExposure(ResourceScope.None)]
143 [MethodImpl(MethodImplOptions.InternalCall)]
144 internal static extern IntPtr GetValueInternal(RuntimeTypeHandle handle);
146 internal RuntimeTypeHandle(RuntimeType type)
151 internal bool IsNullHandle()
153 return m_type == null;
156 [System.Security.SecuritySafeCritical] // auto-generated
157 internal static bool IsPrimitive(RuntimeType type)
159 CorElementType corElemType = GetCorElementType(type);
160 return (corElemType >= CorElementType.Boolean && corElemType <= CorElementType.R8) ||
161 corElemType == CorElementType.I ||
162 corElemType == CorElementType.U;
165 [System.Security.SecuritySafeCritical] // auto-generated
166 internal static bool IsByRef(RuntimeType type)
168 CorElementType corElemType = GetCorElementType(type);
169 return (corElemType == CorElementType.ByRef);
172 [System.Security.SecuritySafeCritical] // auto-generated
173 internal static bool IsPointer(RuntimeType type)
175 CorElementType corElemType = GetCorElementType(type);
176 return (corElemType == CorElementType.Ptr);
179 [System.Security.SecuritySafeCritical] // auto-generated
180 internal static bool IsArray(RuntimeType type)
182 CorElementType corElemType = GetCorElementType(type);
183 return (corElemType == CorElementType.Array || corElemType == CorElementType.SzArray);
186 [System.Security.SecuritySafeCritical] // auto-generated
187 internal static bool IsSzArray(RuntimeType type)
189 CorElementType corElemType = GetCorElementType(type);
190 return (corElemType == CorElementType.SzArray);
193 [System.Security.SecuritySafeCritical] // auto-generated
194 internal static bool HasElementType(RuntimeType type)
196 CorElementType corElemType = GetCorElementType(type);
198 return ((corElemType == CorElementType.Array || corElemType == CorElementType.SzArray) // IsArray
199 || (corElemType == CorElementType.Ptr) // IsPointer
200 || (corElemType == CorElementType.ByRef)); // IsByRef
204 internal static IntPtr[] CopyRuntimeTypeHandles(RuntimeTypeHandle[] inHandles, out int length)
206 if (inHandles == null || inHandles.Length == 0)
212 IntPtr[] outHandles = new IntPtr[inHandles.Length];
213 for (int i = 0; i < inHandles.Length; i++)
215 outHandles[i] = inHandles[i].Value;
217 length = outHandles.Length;
222 internal static IntPtr[] CopyRuntimeTypeHandles(Type[] inHandles, out int length)
224 if (inHandles == null || inHandles.Length == 0)
230 IntPtr[] outHandles = new IntPtr[inHandles.Length];
231 for (int i = 0; i < inHandles.Length; i++)
233 outHandles[i] = inHandles[i].GetTypeHandleInternal().Value;
235 length = outHandles.Length;
239 [System.Security.SecurityCritical] // auto-generated
240 [ResourceExposure(ResourceScope.None)]
241 [MethodImplAttribute(MethodImplOptions.InternalCall)]
242 internal static extern Object CreateInstance(RuntimeType type, bool publicOnly, bool noCheck, ref bool canBeCached, ref RuntimeMethodHandleInternal ctor, ref bool bNeedSecurityCheck);
244 [System.Security.SecurityCritical] // auto-generated
245 [ResourceExposure(ResourceScope.None)]
246 [MethodImplAttribute(MethodImplOptions.InternalCall)]
247 internal static extern Object CreateCaInstance(RuntimeType type, IRuntimeMethodInfo ctor);
249 [System.Security.SecurityCritical] // auto-generated
250 [ResourceExposure(ResourceScope.None)]
251 [MethodImplAttribute(MethodImplOptions.InternalCall)]
252 internal static extern Object Allocate(RuntimeType type);
254 [System.Security.SecurityCritical] // auto-generated
255 [ResourceExposure(ResourceScope.None)]
256 [MethodImplAttribute(MethodImplOptions.InternalCall)]
257 internal static extern Object CreateInstanceForAnotherGenericParameter(RuntimeType type, RuntimeType genericParameter);
259 internal RuntimeType GetRuntimeType()
264 [System.Security.SecurityCritical] // auto-generated
265 [ResourceExposure(ResourceScope.None)]
266 [MethodImplAttribute(MethodImplOptions.InternalCall)]
267 internal extern static CorElementType GetCorElementType(RuntimeType type);
269 [System.Security.SecuritySafeCritical] // auto-generated
270 [ResourceExposure(ResourceScope.None)]
271 [MethodImplAttribute(MethodImplOptions.InternalCall)]
272 internal extern static RuntimeAssembly GetAssembly(RuntimeType type);
274 [System.Security.SecuritySafeCritical] // auto-generated
275 [ResourceExposure(ResourceScope.None)]
276 [MethodImplAttribute(MethodImplOptions.InternalCall)]
277 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
278 internal extern static RuntimeModule GetModule(RuntimeType type);
280 [CLSCompliant(false)]
281 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
282 public ModuleHandle GetModuleHandle()
284 return new ModuleHandle(RuntimeTypeHandle.GetModule(m_type));
287 [System.Security.SecuritySafeCritical]
288 [ResourceExposure(ResourceScope.None)]
289 [MethodImplAttribute(MethodImplOptions.InternalCall)]
290 internal extern static RuntimeType GetBaseType(RuntimeType type);
292 [System.Security.SecurityCritical] // auto-generated
293 [ResourceExposure(ResourceScope.None)]
294 [MethodImplAttribute(MethodImplOptions.InternalCall)]
295 internal extern static TypeAttributes GetAttributes(RuntimeType type);
297 [System.Security.SecuritySafeCritical] // auto-generated
298 [ResourceExposure(ResourceScope.None)]
299 [MethodImplAttribute(MethodImplOptions.InternalCall)]
300 internal extern static RuntimeType GetElementType(RuntimeType type);
302 [System.Security.SecurityCritical] // auto-generated
303 [ResourceExposure(ResourceScope.None)]
304 [MethodImplAttribute(MethodImplOptions.InternalCall)]
305 internal extern static bool CompareCanonicalHandles(RuntimeType left, RuntimeType right);
307 [System.Security.SecurityCritical] // auto-generated
308 [ResourceExposure(ResourceScope.None)]
309 [MethodImplAttribute(MethodImplOptions.InternalCall)]
310 internal extern static int GetArrayRank(RuntimeType type);
312 [System.Security.SecurityCritical] // auto-generated
313 [ResourceExposure(ResourceScope.None)]
314 [MethodImplAttribute(MethodImplOptions.InternalCall)]
315 internal extern static int GetToken(RuntimeType type);
317 [System.Security.SecuritySafeCritical] // auto-generated
318 [ResourceExposure(ResourceScope.None)]
319 [MethodImplAttribute(MethodImplOptions.InternalCall)]
320 internal extern static RuntimeMethodHandleInternal GetMethodAt(RuntimeType type, int slot);
322 // This is managed wrapper for MethodTable::IntroducedMethodIterator
323 internal struct IntroducedMethodEnumerator
326 RuntimeMethodHandleInternal _handle;
328 [System.Security.SecuritySafeCritical] // auto-generated
329 internal IntroducedMethodEnumerator(RuntimeType type)
331 _handle = RuntimeTypeHandle.GetFirstIntroducedMethod(type);
335 [System.Security.SecuritySafeCritical] // auto-generated
336 public bool MoveNext()
342 else if (_handle.Value != IntPtr.Zero)
344 RuntimeTypeHandle.GetNextIntroducedMethod(ref _handle);
346 return !(_handle.Value == IntPtr.Zero);
349 public RuntimeMethodHandleInternal Current
356 // Glue to make this work nicely with C# foreach statement
357 public IntroducedMethodEnumerator GetEnumerator()
363 internal static IntroducedMethodEnumerator GetIntroducedMethods(RuntimeType type)
365 return new IntroducedMethodEnumerator(type);
368 [System.Security.SecurityCritical] // auto-generated
369 [ResourceExposure(ResourceScope.None)]
370 [MethodImplAttribute(MethodImplOptions.InternalCall)]
371 private static extern RuntimeMethodHandleInternal GetFirstIntroducedMethod(RuntimeType type);
373 [System.Security.SecurityCritical] // auto-generated
374 [ResourceExposure(ResourceScope.None)]
375 [MethodImplAttribute(MethodImplOptions.InternalCall)]
376 private static extern void GetNextIntroducedMethod(ref RuntimeMethodHandleInternal method);
378 [System.Security.SecurityCritical] // auto-generated
379 [ResourceExposure(ResourceScope.None)]
380 [MethodImplAttribute(MethodImplOptions.InternalCall)]
381 internal extern static bool GetFields(RuntimeType type, IntPtr* result, int* count);
383 [System.Security.SecurityCritical] // auto-generated
384 [ResourceExposure(ResourceScope.AppDomain)]
385 [MethodImplAttribute(MethodImplOptions.InternalCall)]
386 internal extern static Type[] GetInterfaces(RuntimeType type);
388 [System.Security.SecurityCritical] // auto-generated
389 [ResourceExposure(ResourceScope.None)]
390 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
391 [SuppressUnmanagedCodeSecurity]
392 private extern static void GetConstraints(RuntimeTypeHandle handle, ObjectHandleOnStack types);
394 [System.Security.SecuritySafeCritical] // auto-generated
395 internal Type[] GetConstraints()
398 GetConstraints(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types));
403 [System.Security.SecurityCritical] // auto-generated
404 [ResourceExposure(ResourceScope.AppDomain)]
405 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
406 [SuppressUnmanagedCodeSecurity]
407 private extern static IntPtr GetGCHandle(RuntimeTypeHandle handle, GCHandleType type);
409 [System.Security.SecurityCritical] // auto-generated
410 internal IntPtr GetGCHandle(GCHandleType type)
412 return GetGCHandle(GetNativeHandle(), type);
415 [System.Security.SecurityCritical] // auto-generated
416 [ResourceExposure(ResourceScope.None)]
417 [MethodImplAttribute(MethodImplOptions.InternalCall)]
418 internal extern static int GetNumVirtuals(RuntimeType type);
420 [System.Security.SecurityCritical] // auto-generated
421 [ResourceExposure(ResourceScope.None)]
422 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
423 [SuppressUnmanagedCodeSecurity]
424 private extern static void VerifyInterfaceIsImplemented(RuntimeTypeHandle handle, RuntimeTypeHandle interfaceHandle);
426 [System.Security.SecuritySafeCritical] // auto-generated
427 internal void VerifyInterfaceIsImplemented(RuntimeTypeHandle interfaceHandle)
429 VerifyInterfaceIsImplemented(GetNativeHandle(), interfaceHandle.GetNativeHandle());
432 [System.Security.SecurityCritical] // auto-generated
433 [ResourceExposure(ResourceScope.None)]
434 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
435 [SuppressUnmanagedCodeSecurity]
436 private extern static int GetInterfaceMethodImplementationSlot(RuntimeTypeHandle handle, RuntimeTypeHandle interfaceHandle, RuntimeMethodHandleInternal interfaceMethodHandle);
438 [System.Security.SecuritySafeCritical] // auto-generated
439 [ResourceExposure(ResourceScope.None)]
440 [ResourceConsumption(ResourceScope.AppDomain, ResourceScope.AppDomain)]
441 internal int GetInterfaceMethodImplementationSlot(RuntimeTypeHandle interfaceHandle, RuntimeMethodHandleInternal interfaceMethodHandle)
443 return GetInterfaceMethodImplementationSlot(GetNativeHandle(), interfaceHandle.GetNativeHandle(), interfaceMethodHandle);
446 [System.Security.SecurityCritical] // auto-generated
447 [ResourceExposure(ResourceScope.None)]
448 [MethodImplAttribute(MethodImplOptions.InternalCall)]
449 internal extern static bool IsComObject(RuntimeType type, bool isGenericCOM);
451 [System.Security.SecurityCritical] // auto-generated
452 [ResourceExposure(ResourceScope.None)]
453 [MethodImplAttribute(MethodImplOptions.InternalCall)]
454 internal extern static bool IsContextful(RuntimeType type);
456 [System.Security.SecurityCritical] // auto-generated
457 [ResourceExposure(ResourceScope.None)]
458 [MethodImplAttribute(MethodImplOptions.InternalCall)]
459 internal extern static bool IsInterface(RuntimeType type);
461 [System.Security.SecurityCritical] // auto-generated
462 [ResourceExposure(ResourceScope.None)]
463 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
464 [SuppressUnmanagedCodeSecurity]
465 [return: MarshalAs(UnmanagedType.Bool)]
466 private extern static bool _IsVisible(RuntimeTypeHandle typeHandle);
468 [System.Security.SecuritySafeCritical] // auto-generated
469 internal static bool IsVisible(RuntimeType type)
471 return _IsVisible(new RuntimeTypeHandle(type));
474 [System.Security.SecurityCritical] // auto-generated
475 [ResourceExposure(ResourceScope.None)]
476 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
477 [SuppressUnmanagedCodeSecurity]
478 [return: MarshalAs(UnmanagedType.Bool)]
479 private static extern bool IsSecurityCritical(RuntimeTypeHandle typeHandle);
481 [System.Security.SecuritySafeCritical] // auto-generated
482 internal bool IsSecurityCritical()
484 return IsSecurityCritical(GetNativeHandle());
488 [System.Security.SecurityCritical] // auto-generated
489 [ResourceExposure(ResourceScope.None)]
490 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
491 [SuppressUnmanagedCodeSecurity]
492 [return: MarshalAs(UnmanagedType.Bool)]
493 private static extern bool IsSecuritySafeCritical(RuntimeTypeHandle typeHandle);
495 [System.Security.SecuritySafeCritical] // auto-generated
496 internal bool IsSecuritySafeCritical()
498 return IsSecuritySafeCritical(GetNativeHandle());
501 [System.Security.SecurityCritical] // auto-generated
502 [ResourceExposure(ResourceScope.None)]
503 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
504 [SuppressUnmanagedCodeSecurity]
505 [return: MarshalAs(UnmanagedType.Bool)]
506 private static extern bool IsSecurityTransparent(RuntimeTypeHandle typeHandle);
508 [System.Security.SecuritySafeCritical] // auto-generated
509 internal bool IsSecurityTransparent()
511 return IsSecurityTransparent(GetNativeHandle());
514 [System.Security.SecurityCritical] // auto-generated
515 [ResourceExposure(ResourceScope.None)]
516 [MethodImplAttribute(MethodImplOptions.InternalCall)]
517 internal extern static bool HasProxyAttribute(RuntimeType type);
519 [System.Security.SecuritySafeCritical]
520 [ResourceExposure(ResourceScope.None)]
521 [MethodImplAttribute(MethodImplOptions.InternalCall)]
522 internal extern static bool IsValueType(RuntimeType type);
524 [System.Security.SecurityCritical] // auto-generated
525 [ResourceExposure(ResourceScope.None)]
526 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
527 [SuppressUnmanagedCodeSecurity]
528 private extern static void ConstructName(RuntimeTypeHandle handle, TypeNameFormatFlags formatFlags, StringHandleOnStack retString);
530 [System.Security.SecuritySafeCritical] // auto-generated
531 internal string ConstructName(TypeNameFormatFlags formatFlags)
534 ConstructName(GetNativeHandle(), formatFlags, JitHelpers.GetStringHandleOnStack(ref name));
538 [System.Security.SecurityCritical] // auto-generated
539 [ResourceExposure(ResourceScope.None)]
540 [MethodImplAttribute(MethodImplOptions.InternalCall)]
541 private extern static void* _GetUtf8Name(RuntimeType type);
543 [System.Security.SecuritySafeCritical] // auto-generated
544 internal static Utf8String GetUtf8Name(RuntimeType type)
546 return new Utf8String(_GetUtf8Name(type));
549 [System.Security.SecuritySafeCritical] // auto-generated
550 [ResourceExposure(ResourceScope.None)]
551 [MethodImplAttribute(MethodImplOptions.InternalCall)]
552 internal extern static bool CanCastTo(RuntimeType type, RuntimeType target);
554 [System.Security.SecurityCritical] // auto-generated
555 [ResourceExposure(ResourceScope.None)]
556 [MethodImplAttribute(MethodImplOptions.InternalCall)]
557 internal extern static RuntimeType GetDeclaringType(RuntimeType type);
559 [System.Security.SecuritySafeCritical] // auto-generated
560 [ResourceExposure(ResourceScope.None)]
561 [MethodImplAttribute(MethodImplOptions.InternalCall)]
562 internal extern static IRuntimeMethodInfo GetDeclaringMethod(RuntimeType type);
564 [System.Security.SecurityCritical] // auto-generated
565 [ResourceExposure(ResourceScope.None)]
566 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
567 [SuppressUnmanagedCodeSecurity]
568 private extern static void GetDefaultConstructor(RuntimeTypeHandle handle, ObjectHandleOnStack method);
570 [System.Security.SecuritySafeCritical] // auto-generated
571 internal IRuntimeMethodInfo GetDefaultConstructor()
573 IRuntimeMethodInfo ctor = null;
574 GetDefaultConstructor(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref ctor));
578 [System.Security.SecurityCritical] // auto-generated
579 [ResourceExposure(ResourceScope.None)]
580 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
581 [SuppressUnmanagedCodeSecurity]
582 private extern static void GetTypeByName(string name, bool throwOnError, bool ignoreCase, bool reflectionOnly, StackCrawlMarkHandle stackMark,
583 #if FEATURE_HOSTED_BINDER
584 IntPtr pPrivHostBinder,
586 bool loadTypeFromPartialName, ObjectHandleOnStack type);
588 #if FEATURE_HOSTED_BINDER
589 // Wrapper function to reduce the need for ifdefs.
590 internal static RuntimeType GetTypeByName(string name, bool throwOnError, bool ignoreCase, bool reflectionOnly, ref StackCrawlMark stackMark, bool loadTypeFromPartialName)
592 return GetTypeByName(name, throwOnError, ignoreCase, reflectionOnly, ref stackMark, IntPtr.Zero, loadTypeFromPartialName);
596 [System.Security.SecuritySafeCritical] // auto-generated
597 internal static RuntimeType GetTypeByName(string name, bool throwOnError, bool ignoreCase, bool reflectionOnly, ref StackCrawlMark stackMark,
598 #if FEATURE_HOSTED_BINDER
599 IntPtr pPrivHostBinder,
601 bool loadTypeFromPartialName)
603 if (name == null || name.Length == 0)
606 throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr"));
611 RuntimeType type = null;
613 GetTypeByName(name, throwOnError, ignoreCase, reflectionOnly,
614 JitHelpers.GetStackCrawlMarkHandle(ref stackMark),
615 #if FEATURE_HOSTED_BINDER
618 loadTypeFromPartialName, JitHelpers.GetObjectHandleOnStack(ref type));
623 internal static Type GetTypeByName(string name, ref StackCrawlMark stackMark)
625 return GetTypeByName(name, false, false, false, ref stackMark, false);
628 [System.Security.SecurityCritical] // auto-generated
629 [ResourceExposure(ResourceScope.None)]
630 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
631 [SuppressUnmanagedCodeSecurity]
632 private extern static void GetTypeByNameUsingCARules(string name, RuntimeModule scope, ObjectHandleOnStack type);
634 [System.Security.SecuritySafeCritical] // auto-generated
635 internal static RuntimeType GetTypeByNameUsingCARules(string name, RuntimeModule scope)
637 if (name == null || name.Length == 0)
638 throw new ArgumentException("name");
639 Contract.EndContractBlock();
641 RuntimeType type = null;
642 GetTypeByNameUsingCARules(name, scope.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
647 [System.Security.SecurityCritical] // auto-generated
648 [ResourceExposure(ResourceScope.None)]
649 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
650 [SuppressUnmanagedCodeSecurity]
651 internal extern static void GetInstantiation(RuntimeTypeHandle type, ObjectHandleOnStack types, bool fAsRuntimeTypeArray);
653 [System.Security.SecuritySafeCritical] // auto-generated
654 internal RuntimeType[] GetInstantiationInternal()
656 RuntimeType[] types = null;
657 GetInstantiation(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types), true);
661 [System.Security.SecuritySafeCritical] // auto-generated
662 internal Type[] GetInstantiationPublic()
665 GetInstantiation(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types), false);
669 [System.Security.SecurityCritical] // auto-generated
670 [ResourceExposure(ResourceScope.None)]
671 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
672 [SuppressUnmanagedCodeSecurity]
673 private extern static void Instantiate(RuntimeTypeHandle handle, IntPtr* pInst, int numGenericArgs, ObjectHandleOnStack type);
675 [System.Security.SecurityCritical] // auto-generated
676 internal RuntimeType Instantiate(Type[] inst)
678 // defensive copy to be sure array is not mutated from the outside during processing
680 IntPtr []instHandles = CopyRuntimeTypeHandles(inst, out instCount);
682 fixed (IntPtr* pInst = instHandles)
684 RuntimeType type = null;
685 Instantiate(GetNativeHandle(), pInst, instCount, JitHelpers.GetObjectHandleOnStack(ref type));
691 [System.Security.SecurityCritical] // auto-generated
692 [ResourceExposure(ResourceScope.None)]
693 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
694 [SuppressUnmanagedCodeSecurity]
695 private extern static void MakeArray(RuntimeTypeHandle handle, int rank, ObjectHandleOnStack type);
697 [System.Security.SecuritySafeCritical] // auto-generated
698 internal RuntimeType MakeArray(int rank)
700 RuntimeType type = null;
701 MakeArray(GetNativeHandle(), rank, JitHelpers.GetObjectHandleOnStack(ref type));
705 [System.Security.SecurityCritical] // auto-generated
706 [ResourceExposure(ResourceScope.None)]
707 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
708 [SuppressUnmanagedCodeSecurity]
709 private extern static void MakeSZArray(RuntimeTypeHandle handle, ObjectHandleOnStack type);
711 [System.Security.SecuritySafeCritical] // auto-generated
712 internal RuntimeType MakeSZArray()
714 RuntimeType type = null;
715 MakeSZArray(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
719 [System.Security.SecurityCritical] // auto-generated
720 [ResourceExposure(ResourceScope.None)]
721 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
722 [SuppressUnmanagedCodeSecurity]
723 private extern static void MakeByRef(RuntimeTypeHandle handle, ObjectHandleOnStack type);
725 [System.Security.SecuritySafeCritical] // auto-generated
726 internal RuntimeType MakeByRef()
728 #if FEATURE_LEGACYNETCF
731 RuntimeType type = null;
732 MakeByRef(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
734 #if FEATURE_LEGACYNETCF
736 if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
743 [System.Security.SecurityCritical] // auto-generated
744 [ResourceExposure(ResourceScope.None)]
745 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
746 [SuppressUnmanagedCodeSecurity]
747 private extern static void MakePointer(RuntimeTypeHandle handle, ObjectHandleOnStack type);
749 [System.Security.SecurityCritical] // auto-generated
750 internal RuntimeType MakePointer()
752 RuntimeType type = null;
753 MakePointer(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
757 [System.Security.SecurityCritical] // auto-generated
758 [ResourceExposure(ResourceScope.None)]
759 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
760 [SuppressUnmanagedCodeSecurity]
761 internal extern static bool IsCollectible(RuntimeTypeHandle handle);
764 [System.Security.SecuritySafeCritical] // auto-generated
766 [ResourceExposure(ResourceScope.None)]
767 [MethodImplAttribute(MethodImplOptions.InternalCall)]
768 internal extern static bool HasInstantiation(RuntimeType type);
770 internal bool HasInstantiation()
772 return HasInstantiation(GetTypeChecked());
775 [System.Security.SecurityCritical] // auto-generated
776 [ResourceExposure(ResourceScope.None)]
777 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
778 [SuppressUnmanagedCodeSecurity]
779 private extern static void GetGenericTypeDefinition(RuntimeTypeHandle type, ObjectHandleOnStack retType);
781 [System.Security.SecuritySafeCritical] // auto-generated
782 internal static RuntimeType GetGenericTypeDefinition(RuntimeType type)
784 RuntimeType retType = type;
786 if (HasInstantiation(retType) && !IsGenericTypeDefinition(retType))
787 GetGenericTypeDefinition(retType.GetTypeHandleInternal(), JitHelpers.GetObjectHandleOnStack(ref retType));
792 [System.Security.SecuritySafeCritical] // auto-generated
793 [ResourceExposure(ResourceScope.None)]
794 [MethodImplAttribute(MethodImplOptions.InternalCall)]
795 internal extern static bool IsGenericTypeDefinition(RuntimeType type);
797 [System.Security.SecuritySafeCritical] // auto-generated
798 [ResourceExposure(ResourceScope.None)]
799 [MethodImplAttribute(MethodImplOptions.InternalCall)]
800 internal extern static bool IsGenericVariable(RuntimeType type);
802 internal bool IsGenericVariable()
804 return IsGenericVariable(GetTypeChecked());
807 [System.Security.SecurityCritical] // auto-generated
808 [ResourceExposure(ResourceScope.None)]
809 [MethodImplAttribute(MethodImplOptions.InternalCall)]
810 private extern static int GetGenericVariableIndex(RuntimeType type);
812 [System.Security.SecuritySafeCritical] // auto-generated
813 internal int GetGenericVariableIndex()
815 RuntimeType type = GetTypeChecked();
817 if (!IsGenericVariable(type))
818 throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericParameter"));
820 return GetGenericVariableIndex(type);
823 [System.Security.SecurityCritical] // auto-generated
824 [ResourceExposure(ResourceScope.None)]
825 [MethodImplAttribute(MethodImplOptions.InternalCall)]
826 internal extern static bool ContainsGenericVariables(RuntimeType handle);
828 [System.Security.SecuritySafeCritical] // auto-generated
829 internal bool ContainsGenericVariables()
831 return ContainsGenericVariables(GetTypeChecked());
834 [System.Security.SecurityCritical] // auto-generated
835 [ResourceExposure(ResourceScope.None)]
836 [MethodImplAttribute(MethodImplOptions.InternalCall)]
837 private extern static bool SatisfiesConstraints(RuntimeType paramType, IntPtr *pTypeContext, int typeContextLength, IntPtr *pMethodContext, int methodContextLength, RuntimeType toType);
839 [System.Security.SecurityCritical]
840 internal static bool SatisfiesConstraints(RuntimeType paramType, RuntimeType[] typeContext, RuntimeType[] methodContext, RuntimeType toType)
842 int typeContextLength;
843 int methodContextLength;
844 IntPtr[] typeContextHandles = CopyRuntimeTypeHandles(typeContext, out typeContextLength);
845 IntPtr[] methodContextHandles = CopyRuntimeTypeHandles(methodContext, out methodContextLength);
847 fixed (IntPtr *pTypeContextHandles = typeContextHandles, pMethodContextHandles = methodContextHandles)
849 bool result = SatisfiesConstraints(paramType, pTypeContextHandles, typeContextLength, pMethodContextHandles, methodContextLength, toType);
851 GC.KeepAlive(typeContext);
852 GC.KeepAlive(methodContext);
858 [System.Security.SecurityCritical] // auto-generated
859 [ResourceExposure(ResourceScope.None)]
860 [MethodImplAttribute(MethodImplOptions.InternalCall)]
861 private extern static IntPtr _GetMetadataImport(RuntimeType type);
863 [System.Security.SecurityCritical] // auto-generated
864 internal static MetadataImport GetMetadataImport(RuntimeType type)
866 return new MetadataImport(_GetMetadataImport(type), type);
869 [System.Security.SecurityCritical] // auto-generated
870 private RuntimeTypeHandle(SerializationInfo info, StreamingContext context)
873 throw new ArgumentNullException("info");
874 Contract.EndContractBlock();
876 RuntimeType m = (RuntimeType)info.GetValue("TypeObj", typeof(RuntimeType));
881 throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
884 [System.Security.SecurityCritical]
885 public void GetObjectData(SerializationInfo info, StreamingContext context)
888 throw new ArgumentNullException("info");
889 Contract.EndContractBlock();
892 throw new SerializationException(Environment.GetResourceString("Serialization_InvalidFieldState"));
894 info.AddValue("TypeObj", m_type, typeof(RuntimeType));
898 [System.Security.SecuritySafeCritical]
899 [ResourceExposure(ResourceScope.None)]
900 [MethodImpl(MethodImplOptions.InternalCall)]
901 internal static extern bool IsEquivalentTo(RuntimeType rtType1, RuntimeType rtType2);
903 [System.Security.SecuritySafeCritical]
904 [ResourceExposure(ResourceScope.None)]
905 [MethodImpl(MethodImplOptions.InternalCall)]
906 internal static extern bool IsEquivalentType(RuntimeType type);
907 #endif // FEATURE_CORECLR
910 // This type is used to remove the expense of having a managed reference object that is dynamically
911 // created when we can prove that we don't need that object. Use of this type requires code to ensure
912 // that the underlying native resource is not freed.
913 // Cases in which this may be used:
914 // 1. When native code calls managed code passing one of these as a parameter
915 // 2. When managed code acquires one of these from an IRuntimeMethodInfo, and ensure that the IRuntimeMethodInfo is preserved
916 // across the lifetime of the RuntimeMethodHandleInternal instance
917 // 3. When another object is used to keep the RuntimeMethodHandleInternal alive. See delegates, CreateInstance cache, Signature structure
918 // When in doubt, do not use.
919 internal struct RuntimeMethodHandleInternal
921 internal static RuntimeMethodHandleInternal EmptyHandle
925 return new RuntimeMethodHandleInternal();
929 internal bool IsNullHandle()
931 return m_handle.IsNull();
934 internal IntPtr Value
944 internal RuntimeMethodHandleInternal(IntPtr value)
949 internal IntPtr m_handle;
952 internal class RuntimeMethodInfoStub : IRuntimeMethodInfo
954 public RuntimeMethodInfoStub(RuntimeMethodHandleInternal methodHandleValue, object keepalive)
956 m_keepalive = keepalive;
957 m_value = methodHandleValue;
961 public RuntimeMethodInfoStub(IntPtr methodHandleValue, object keepalive)
963 m_keepalive = keepalive;
964 m_value = new RuntimeMethodHandleInternal(methodHandleValue);
969 // These unused variables are used to ensure that this class has the same layout as RuntimeMethodInfo
970 #pragma warning disable 169
981 #pragma warning restore 169
982 public RuntimeMethodHandleInternal m_value;
984 RuntimeMethodHandleInternal IRuntimeMethodInfo.Value
993 internal interface IRuntimeMethodInfo
995 RuntimeMethodHandleInternal Value
1002 [System.Runtime.InteropServices.ComVisible(true)]
1003 public unsafe struct RuntimeMethodHandle : ISerializable
1005 // Returns handle for interop with EE. The handle is guaranteed to be non-null.
1006 internal static IRuntimeMethodInfo EnsureNonNullMethodInfo(IRuntimeMethodInfo method)
1009 throw new ArgumentNullException(null, Environment.GetResourceString("Arg_InvalidHandle"));
1013 internal static RuntimeMethodHandle EmptyHandle
1015 get { return new RuntimeMethodHandle(); }
1018 private IRuntimeMethodInfo m_value;
1020 internal RuntimeMethodHandle(IRuntimeMethodInfo method)
1025 internal IRuntimeMethodInfo GetMethodInfo()
1032 private static IntPtr GetValueInternal(RuntimeMethodHandle rmh)
1037 // ISerializable interface
1038 [System.Security.SecurityCritical] // auto-generated
1039 private RuntimeMethodHandle(SerializationInfo info, StreamingContext context)
1042 throw new ArgumentNullException("info");
1043 Contract.EndContractBlock();
1045 MethodBase m =(MethodBase)info.GetValue("MethodObj", typeof(MethodBase));
1047 m_value = m.MethodHandle.m_value;
1049 if (m_value == null)
1050 throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
1053 [System.Security.SecurityCritical]
1054 public void GetObjectData(SerializationInfo info, StreamingContext context)
1057 throw new ArgumentNullException("info");
1058 Contract.EndContractBlock();
1060 if (m_value == null)
1061 throw new SerializationException(Environment.GetResourceString("Serialization_InvalidFieldState"));
1063 // This is either a RuntimeMethodInfo or a RuntimeConstructorInfo
1064 MethodBase methodInfo = RuntimeType.GetMethodBase(m_value);
1066 info.AddValue("MethodObj", methodInfo, typeof(MethodBase));
1071 #if FEATURE_LEGACYNETCF
1072 [SecuritySafeCritical]
1078 return m_value != null ? m_value.Value.Value : IntPtr.Zero;
1082 [SecuritySafeCritical]
1083 public override int GetHashCode()
1085 return ValueType.GetHashCodeOfPtr(Value);
1088 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1089 [SecuritySafeCritical]
1090 public override bool Equals(object obj)
1092 if (!(obj is RuntimeMethodHandle))
1095 RuntimeMethodHandle handle = (RuntimeMethodHandle)obj;
1097 return handle.Value == Value;
1100 public static bool operator ==(RuntimeMethodHandle left, RuntimeMethodHandle right)
1102 return left.Equals(right);
1105 public static bool operator !=(RuntimeMethodHandle left, RuntimeMethodHandle right)
1107 return !left.Equals(right);
1110 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1111 [SecuritySafeCritical]
1112 public bool Equals(RuntimeMethodHandle handle)
1114 return handle.Value == Value;
1118 internal bool IsNullHandle()
1120 return m_value == null;
1123 [System.Security.SecurityCritical] // auto-generated
1124 [ResourceExposure(ResourceScope.None)]
1125 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1126 [SuppressUnmanagedCodeSecurity]
1127 internal extern static IntPtr GetFunctionPointer(RuntimeMethodHandleInternal handle);
1129 [System.Security.SecurityCritical] // auto-generated
1130 public IntPtr GetFunctionPointer()
1132 IntPtr ptr = GetFunctionPointer(EnsureNonNullMethodInfo(m_value).Value);
1133 GC.KeepAlive(m_value);
1137 [System.Security.SecurityCritical] // auto-generated
1138 [ResourceExposure(ResourceScope.None)]
1139 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1140 internal unsafe extern static void CheckLinktimeDemands(IRuntimeMethodInfo method, RuntimeModule module, bool isDecoratedTargetSecurityTransparent);
1142 [System.Security.SecurityCritical] // auto-generated
1143 [ResourceExposure(ResourceScope.None)]
1144 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1145 [SuppressUnmanagedCodeSecurity]
1146 internal extern static bool IsCAVisibleFromDecoratedType(
1147 RuntimeTypeHandle attrTypeHandle,
1148 IRuntimeMethodInfo attrCtor,
1149 RuntimeTypeHandle sourceTypeHandle,
1150 RuntimeModule sourceModule);
1152 [System.Security.SecurityCritical] // auto-generated
1153 [ResourceExposure(ResourceScope.None)]
1154 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1155 private static extern IRuntimeMethodInfo _GetCurrentMethod(ref StackCrawlMark stackMark);
1156 [System.Security.SecuritySafeCritical] // auto-generated
1157 internal static IRuntimeMethodInfo GetCurrentMethod(ref StackCrawlMark stackMark)
1159 return _GetCurrentMethod(ref stackMark);
1163 [System.Security.SecurityCritical] // auto-generated
1164 [ResourceExposure(ResourceScope.None)]
1165 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1166 internal static extern MethodAttributes GetAttributes(RuntimeMethodHandleInternal method);
1168 [System.Security.SecurityCritical] // auto-generated
1169 internal static MethodAttributes GetAttributes(IRuntimeMethodInfo method)
1171 MethodAttributes retVal = RuntimeMethodHandle.GetAttributes(method.Value);
1172 GC.KeepAlive(method);
1176 [System.Security.SecuritySafeCritical] // auto-generated
1177 [ResourceExposure(ResourceScope.None)]
1178 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1179 internal static extern MethodImplAttributes GetImplAttributes(IRuntimeMethodInfo method);
1181 [System.Security.SecurityCritical] // auto-generated
1182 [ResourceExposure(ResourceScope.None)]
1183 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1184 [SuppressUnmanagedCodeSecurity]
1185 private extern static void ConstructInstantiation(IRuntimeMethodInfo method, TypeNameFormatFlags format, StringHandleOnStack retString);
1187 [System.Security.SecuritySafeCritical] // auto-generated
1188 internal static string ConstructInstantiation(IRuntimeMethodInfo method, TypeNameFormatFlags format)
1191 ConstructInstantiation(EnsureNonNullMethodInfo(method), format, JitHelpers.GetStringHandleOnStack(ref name));
1195 [System.Security.SecurityCritical] // auto-generated
1196 [ResourceExposure(ResourceScope.None)]
1197 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1198 internal extern static RuntimeType GetDeclaringType(RuntimeMethodHandleInternal method);
1200 [System.Security.SecuritySafeCritical] // auto-generated
1201 internal static RuntimeType GetDeclaringType(IRuntimeMethodInfo method)
1203 RuntimeType type = RuntimeMethodHandle.GetDeclaringType(method.Value);
1204 GC.KeepAlive(method);
1208 [System.Security.SecurityCritical] // auto-generated
1209 [ResourceExposure(ResourceScope.None)]
1210 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1211 internal extern static int GetSlot(RuntimeMethodHandleInternal method);
1213 [System.Security.SecurityCritical] // auto-generated
1214 internal static int GetSlot(IRuntimeMethodInfo method)
1216 Contract.Requires(method != null);
1218 int slot = RuntimeMethodHandle.GetSlot(method.Value);
1219 GC.KeepAlive(method);
1223 [System.Security.SecurityCritical] // auto-generated
1224 [ResourceExposure(ResourceScope.None)]
1225 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1226 internal extern static int GetMethodDef(IRuntimeMethodInfo method);
1228 [System.Security.SecurityCritical] // auto-generated
1229 [ResourceExposure(ResourceScope.None)]
1230 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1231 internal extern static string GetName(RuntimeMethodHandleInternal method);
1233 [System.Security.SecurityCritical] // auto-generated
1234 internal static string GetName(IRuntimeMethodInfo method)
1236 string name = RuntimeMethodHandle.GetName(method.Value);
1237 GC.KeepAlive(method);
1241 [System.Security.SecurityCritical] // auto-generated
1242 [ResourceExposure(ResourceScope.None)]
1243 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1244 private extern static void* _GetUtf8Name(RuntimeMethodHandleInternal method);
1246 [System.Security.SecurityCritical] // auto-generated
1247 internal static Utf8String GetUtf8Name(RuntimeMethodHandleInternal method)
1249 return new Utf8String(_GetUtf8Name(method));
1252 [System.Security.SecurityCritical] // auto-generated
1253 [ResourceExposure(ResourceScope.None)]
1254 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1255 internal static extern bool MatchesNameHash(RuntimeMethodHandleInternal method, uint hash);
1257 [System.Security.SecuritySafeCritical] // auto-generated
1258 [ResourceExposure(ResourceScope.None)]
1259 [DebuggerStepThroughAttribute]
1260 [Diagnostics.DebuggerHidden]
1261 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1262 internal extern static object InvokeMethod(object target, object[] arguments, Signature sig, bool constructor);
1264 #region Private Invocation Helpers
1265 [System.Security.SecurityCritical] // auto-generated
1266 internal static INVOCATION_FLAGS GetSecurityFlags(IRuntimeMethodInfo handle)
1268 return (INVOCATION_FLAGS)RuntimeMethodHandle.GetSpecialSecurityFlags(handle);
1271 [System.Security.SecurityCritical] // auto-generated
1272 [ResourceExposure(ResourceScope.None)]
1273 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1274 static extern internal uint GetSpecialSecurityFlags(IRuntimeMethodInfo method);
1276 [System.Security.SecurityCritical] // auto-generated
1277 [ResourceExposure(ResourceScope.None)]
1278 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1279 static extern internal void PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, uint invocationFlags);
1281 [System.Security.SecurityCritical]
1282 static internal void PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, uint invocationFlags)
1284 RuntimeMethodHandle.PerformSecurityCheck(obj, method.Value, parent, invocationFlags);
1285 GC.KeepAlive(method);
1290 [System.Security.SecuritySafeCritical] // auto-generated
1291 [DebuggerStepThroughAttribute]
1292 [Diagnostics.DebuggerHidden]
1293 [ResourceExposure(ResourceScope.None)]
1294 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1295 internal extern static void SerializationInvoke(IRuntimeMethodInfo method,
1296 Object target, SerializationInfo info, ref StreamingContext context);
1298 // This returns true if the token is SecurityTransparent:
1299 // just the token - does not consider including module/type etc.
1300 [System.Security.SecurityCritical] // auto-generated
1301 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1302 internal static extern bool _IsTokenSecurityTransparent(RuntimeModule module, int metaDataToken);
1305 [System.Security.SecuritySafeCritical] // auto-generated
1307 [System.Security.SecurityCritical]
1309 internal static bool IsTokenSecurityTransparent(Module module, int metaDataToken)
1311 return _IsTokenSecurityTransparent(module.ModuleHandle.GetRuntimeModule(), metaDataToken);
1314 [System.Security.SecurityCritical] // auto-generated
1315 [ResourceExposure(ResourceScope.None)]
1316 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1317 [SuppressUnmanagedCodeSecurity]
1318 [return: MarshalAs(UnmanagedType.Bool)]
1319 private static extern bool _IsSecurityCritical(IRuntimeMethodInfo method);
1321 [System.Security.SecuritySafeCritical] // auto-generated
1322 internal static bool IsSecurityCritical(IRuntimeMethodInfo method)
1324 return _IsSecurityCritical(method);
1327 [System.Security.SecurityCritical] // auto-generated
1328 [ResourceExposure(ResourceScope.None)]
1329 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1330 [SuppressUnmanagedCodeSecurity]
1331 [return: MarshalAs(UnmanagedType.Bool)]
1332 private static extern bool _IsSecuritySafeCritical(IRuntimeMethodInfo method);
1334 [System.Security.SecuritySafeCritical] // auto-generated
1335 internal static bool IsSecuritySafeCritical(IRuntimeMethodInfo method)
1337 return _IsSecuritySafeCritical(method);
1340 [System.Security.SecurityCritical] // auto-generated
1341 [ResourceExposure(ResourceScope.None)]
1342 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1343 [SuppressUnmanagedCodeSecurity]
1344 [return: MarshalAs(UnmanagedType.Bool)]
1345 private static extern bool _IsSecurityTransparent(IRuntimeMethodInfo method);
1347 [System.Security.SecuritySafeCritical] // auto-generated
1348 internal static bool IsSecurityTransparent(IRuntimeMethodInfo method)
1350 return _IsSecurityTransparent(method);
1353 [System.Security.SecurityCritical] // auto-generated
1354 [ResourceExposure(ResourceScope.None)]
1355 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1356 [SuppressUnmanagedCodeSecurity]
1357 private extern static void GetMethodInstantiation(RuntimeMethodHandleInternal method, ObjectHandleOnStack types, bool fAsRuntimeTypeArray);
1359 [System.Security.SecuritySafeCritical] // auto-generated
1360 internal static RuntimeType[] GetMethodInstantiationInternal(IRuntimeMethodInfo method)
1362 RuntimeType[] types = null;
1363 GetMethodInstantiation(EnsureNonNullMethodInfo(method).Value, JitHelpers.GetObjectHandleOnStack(ref types), true);
1364 GC.KeepAlive(method);
1368 [System.Security.SecuritySafeCritical] // auto-generated
1369 internal static RuntimeType[] GetMethodInstantiationInternal(RuntimeMethodHandleInternal method)
1371 RuntimeType[] types = null;
1372 GetMethodInstantiation(method, JitHelpers.GetObjectHandleOnStack(ref types), true);
1376 [System.Security.SecuritySafeCritical] // auto-generated
1377 internal static Type[] GetMethodInstantiationPublic(IRuntimeMethodInfo method)
1379 RuntimeType[] types = null;
1380 GetMethodInstantiation(EnsureNonNullMethodInfo(method).Value, JitHelpers.GetObjectHandleOnStack(ref types), false);
1381 GC.KeepAlive(method);
1385 [System.Security.SecurityCritical] // auto-generated
1386 [ResourceExposure(ResourceScope.None)]
1387 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1388 internal extern static bool HasMethodInstantiation(RuntimeMethodHandleInternal method);
1390 [System.Security.SecuritySafeCritical] // auto-generated
1391 internal static bool HasMethodInstantiation(IRuntimeMethodInfo method)
1393 bool fRet = RuntimeMethodHandle.HasMethodInstantiation(method.Value);
1394 GC.KeepAlive(method);
1398 [System.Security.SecurityCritical] // auto-generated
1399 [ResourceExposure(ResourceScope.None)]
1400 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1401 internal extern static RuntimeMethodHandleInternal GetStubIfNeeded(RuntimeMethodHandleInternal method, RuntimeType declaringType, RuntimeType[] methodInstantiation);
1403 [System.Security.SecurityCritical] // auto-generated
1404 [ResourceExposure(ResourceScope.None)]
1405 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1406 internal extern static RuntimeMethodHandleInternal GetMethodFromCanonical(RuntimeMethodHandleInternal method, RuntimeType declaringType);
1408 [System.Security.SecurityCritical] // auto-generated
1409 [ResourceExposure(ResourceScope.None)]
1410 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1411 internal extern static bool IsGenericMethodDefinition(RuntimeMethodHandleInternal method);
1413 [System.Security.SecuritySafeCritical] // auto-generated
1414 internal static bool IsGenericMethodDefinition(IRuntimeMethodInfo method)
1416 bool fRet = RuntimeMethodHandle.IsGenericMethodDefinition(method.Value);
1417 GC.KeepAlive(method);
1422 [System.Security.SecuritySafeCritical] // auto-generated
1423 [ResourceExposure(ResourceScope.None)]
1424 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1425 internal extern static bool IsTypicalMethodDefinition(IRuntimeMethodInfo method);
1427 [System.Security.SecurityCritical] // auto-generated
1428 [ResourceExposure(ResourceScope.None)]
1429 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1430 [SuppressUnmanagedCodeSecurity]
1431 private extern static void GetTypicalMethodDefinition(IRuntimeMethodInfo method, ObjectHandleOnStack outMethod);
1433 [System.Security.SecuritySafeCritical] // auto-generated
1434 internal static IRuntimeMethodInfo GetTypicalMethodDefinition(IRuntimeMethodInfo method)
1436 if (!IsTypicalMethodDefinition(method))
1437 GetTypicalMethodDefinition(method, JitHelpers.GetObjectHandleOnStack(ref method));
1442 [System.Security.SecurityCritical] // auto-generated
1443 [ResourceExposure(ResourceScope.None)]
1444 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1445 [SuppressUnmanagedCodeSecurity]
1446 private extern static void StripMethodInstantiation(IRuntimeMethodInfo method, ObjectHandleOnStack outMethod);
1448 [System.Security.SecuritySafeCritical] // auto-generated
1449 internal static IRuntimeMethodInfo StripMethodInstantiation(IRuntimeMethodInfo method)
1451 IRuntimeMethodInfo strippedMethod = method;
1453 StripMethodInstantiation(method, JitHelpers.GetObjectHandleOnStack(ref strippedMethod));
1455 return strippedMethod;
1458 [System.Security.SecuritySafeCritical] // auto-generated
1459 [ResourceExposure(ResourceScope.None)]
1460 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1461 internal extern static bool IsDynamicMethod(RuntimeMethodHandleInternal method);
1463 [System.Security.SecurityCritical] // auto-generated
1464 [ResourceExposure(ResourceScope.None)]
1465 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1466 [SuppressUnmanagedCodeSecurity]
1467 internal extern static void Destroy(RuntimeMethodHandleInternal method);
1469 [System.Security.SecuritySafeCritical] // auto-generated
1470 [ResourceExposure(ResourceScope.None)]
1471 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1472 internal extern static Resolver GetResolver(RuntimeMethodHandleInternal method);
1474 [System.Security.SecurityCritical] // auto-generated
1475 [ResourceExposure(ResourceScope.None)]
1476 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1477 [SuppressUnmanagedCodeSecurity]
1478 private static extern void GetCallerType(StackCrawlMarkHandle stackMark, ObjectHandleOnStack retType);
1480 [System.Security.SecuritySafeCritical] // auto-generated
1481 internal static RuntimeType GetCallerType(ref StackCrawlMark stackMark)
1483 RuntimeType type = null;
1484 GetCallerType(JitHelpers.GetStackCrawlMarkHandle(ref stackMark), JitHelpers.GetObjectHandleOnStack(ref type));
1488 [ResourceExposure(ResourceScope.None)]
1489 [MethodImpl(MethodImplOptions.InternalCall)]
1490 [System.Security.SecuritySafeCritical] // auto-generated
1491 internal extern static MethodBody GetMethodBody(IRuntimeMethodInfo method, RuntimeType declaringType);
1493 [System.Security.SecurityCritical] // auto-generated
1494 [ResourceExposure(ResourceScope.None)]
1495 [MethodImpl(MethodImplOptions.InternalCall)]
1496 internal extern static bool IsConstructor(RuntimeMethodHandleInternal method);
1498 [System.Security.SecurityCritical] // auto-generated
1499 [ResourceExposure(ResourceScope.None)]
1500 [MethodImpl(MethodImplOptions.InternalCall)]
1501 internal extern static LoaderAllocator GetLoaderAllocator(RuntimeMethodHandleInternal method);
1504 // This type is used to remove the expense of having a managed reference object that is dynamically
1505 // created when we can prove that we don't need that object. Use of this type requires code to ensure
1506 // that the underlying native resource is not freed.
1507 // Cases in which this may be used:
1508 // 1. When native code calls managed code passing one of these as a parameter
1509 // 2. When managed code acquires one of these from an RtFieldInfo, and ensure that the RtFieldInfo is preserved
1510 // across the lifetime of the RuntimeFieldHandleInternal instance
1511 // 3. When another object is used to keep the RuntimeFieldHandleInternal alive.
1512 // When in doubt, do not use.
1513 internal struct RuntimeFieldHandleInternal
1515 internal static RuntimeFieldHandleInternal EmptyHandle
1519 return new RuntimeFieldHandleInternal();
1523 internal bool IsNullHandle()
1525 return m_handle.IsNull();
1528 internal IntPtr Value
1538 internal RuntimeFieldHandleInternal(IntPtr value)
1543 internal IntPtr m_handle;
1546 internal interface IRuntimeFieldInfo
1548 RuntimeFieldHandleInternal Value
1554 [StructLayout(LayoutKind.Sequential)]
1555 internal class RuntimeFieldInfoStub : IRuntimeFieldInfo
1557 [SecuritySafeCritical]
1558 public RuntimeFieldInfoStub(IntPtr methodHandleValue, object keepalive)
1560 m_keepalive = keepalive;
1561 m_fieldHandle = new RuntimeFieldHandleInternal(methodHandleValue);
1564 // These unused variables are used to ensure that this class has the same layout as RuntimeFieldInfo
1565 #pragma warning disable 169
1571 #if FEATURE_REMOTING
1574 RuntimeFieldHandleInternal m_fieldHandle;
1575 #pragma warning restore 169
1577 RuntimeFieldHandleInternal IRuntimeFieldInfo.Value
1581 return m_fieldHandle;
1587 [System.Runtime.InteropServices.ComVisible(true)]
1588 public unsafe struct RuntimeFieldHandle : ISerializable
1590 // Returns handle for interop with EE. The handle is guaranteed to be non-null.
1591 internal RuntimeFieldHandle GetNativeHandle()
1593 // Create local copy to avoid ----s
1594 IRuntimeFieldInfo field = m_ptr;
1596 throw new ArgumentNullException(null, Environment.GetResourceString("Arg_InvalidHandle"));
1597 return new RuntimeFieldHandle(field);
1600 private IRuntimeFieldInfo m_ptr;
1602 internal RuntimeFieldHandle(IRuntimeFieldInfo fieldInfo)
1607 internal IRuntimeFieldInfo GetRuntimeFieldInfo()
1614 #if FEATURE_LEGACYNETCF
1615 [SecuritySafeCritical]
1621 return m_ptr != null ? m_ptr.Value.Value : IntPtr.Zero;
1625 internal bool IsNullHandle()
1627 return m_ptr == null;
1630 [SecuritySafeCritical]
1631 public override int GetHashCode()
1633 return ValueType.GetHashCodeOfPtr(Value);
1636 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1637 [SecuritySafeCritical]
1638 public override bool Equals(object obj)
1640 if (!(obj is RuntimeFieldHandle))
1643 RuntimeFieldHandle handle = (RuntimeFieldHandle)obj;
1645 return handle.Value == Value;
1648 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1649 [SecuritySafeCritical]
1650 public unsafe bool Equals(RuntimeFieldHandle handle)
1652 return handle.Value == Value;
1655 public static bool operator ==(RuntimeFieldHandle left, RuntimeFieldHandle right)
1657 return left.Equals(right);
1660 public static bool operator !=(RuntimeFieldHandle left, RuntimeFieldHandle right)
1662 return !left.Equals(right);
1665 [System.Security.SecurityCritical] // auto-generated
1666 [ResourceExposure(ResourceScope.None)]
1667 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1668 internal static extern String GetName(RtFieldInfo field);
1670 [System.Security.SecurityCritical] // auto-generated
1671 [ResourceExposure(ResourceScope.None)]
1672 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1673 private static extern unsafe void* _GetUtf8Name(RuntimeFieldHandleInternal field);
1675 [System.Security.SecuritySafeCritical] // auto-generated
1676 internal static unsafe Utf8String GetUtf8Name(RuntimeFieldHandleInternal field) { return new Utf8String(_GetUtf8Name(field)); }
1678 [System.Security.SecurityCritical] // auto-generated
1679 [ResourceExposure(ResourceScope.None)]
1680 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1681 internal static extern bool MatchesNameHash(RuntimeFieldHandleInternal handle, uint hash);
1683 [System.Security.SecurityCritical] // auto-generated
1684 [ResourceExposure(ResourceScope.None)]
1685 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1686 internal static extern FieldAttributes GetAttributes(RuntimeFieldHandleInternal field);
1688 [System.Security.SecurityCritical] // auto-generated
1689 [ResourceExposure(ResourceScope.None)]
1690 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1691 internal static extern RuntimeType GetApproxDeclaringType(RuntimeFieldHandleInternal field);
1693 [System.Security.SecurityCritical] // auto-generated
1694 internal static RuntimeType GetApproxDeclaringType(IRuntimeFieldInfo field)
1696 RuntimeType type = GetApproxDeclaringType(field.Value);
1697 GC.KeepAlive(field);
1701 [System.Security.SecurityCritical] // auto-generated
1702 [ResourceExposure(ResourceScope.None)]
1703 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1704 internal static extern int GetToken(RtFieldInfo field);
1706 [System.Security.SecurityCritical] // auto-generated
1707 [ResourceExposure(ResourceScope.None)]
1708 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1709 internal static extern Object GetValue(RtFieldInfo field, Object instance, RuntimeType fieldType, RuntimeType declaringType, ref bool domainInitialized);
1711 [System.Security.SecurityCritical] // auto-generated
1712 [ResourceExposure(ResourceScope.None)]
1713 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1714 internal static extern Object GetValueDirect(RtFieldInfo field, RuntimeType fieldType, void *pTypedRef, RuntimeType contextType);
1716 [System.Security.SecurityCritical] // auto-generated
1717 [ResourceExposure(ResourceScope.None)]
1718 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1719 internal static extern void SetValue(RtFieldInfo field, Object obj, Object value, RuntimeType fieldType, FieldAttributes fieldAttr, RuntimeType declaringType, ref bool domainInitialized);
1721 [System.Security.SecurityCritical] // auto-generated
1722 [ResourceExposure(ResourceScope.None)]
1723 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1724 internal static extern void SetValueDirect(RtFieldInfo field, RuntimeType fieldType, void* pTypedRef, Object value, RuntimeType contextType);
1726 [System.Security.SecurityCritical] // auto-generated
1727 [ResourceExposure(ResourceScope.None)]
1728 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1729 internal static extern RuntimeFieldHandleInternal GetStaticFieldForGenericType(RuntimeFieldHandleInternal field, RuntimeType declaringType);
1731 [System.Security.SecurityCritical] // auto-generated
1732 [ResourceExposure(ResourceScope.None)]
1733 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1734 internal static extern bool AcquiresContextFromThis(RuntimeFieldHandleInternal field);
1736 [System.Security.SecurityCritical] // auto-generated
1737 [ResourceExposure(ResourceScope.None)]
1738 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1739 [SuppressUnmanagedCodeSecurity]
1740 [return: MarshalAs(UnmanagedType.Bool)]
1741 private static extern bool IsSecurityCritical(RuntimeFieldHandle fieldHandle);
1743 [System.Security.SecuritySafeCritical] // auto-generated
1744 internal bool IsSecurityCritical()
1746 return IsSecurityCritical(GetNativeHandle());
1749 [System.Security.SecurityCritical] // auto-generated
1750 [ResourceExposure(ResourceScope.None)]
1751 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1752 [SuppressUnmanagedCodeSecurity]
1753 [return: MarshalAs(UnmanagedType.Bool)]
1754 private static extern bool IsSecuritySafeCritical(RuntimeFieldHandle fieldHandle);
1756 [System.Security.SecuritySafeCritical] // auto-generated
1757 internal bool IsSecuritySafeCritical()
1759 return IsSecuritySafeCritical(GetNativeHandle());
1762 [System.Security.SecurityCritical] // auto-generated
1763 [ResourceExposure(ResourceScope.None)]
1764 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1765 [SuppressUnmanagedCodeSecurity]
1766 [return: MarshalAs(UnmanagedType.Bool)]
1767 private static extern bool IsSecurityTransparent(RuntimeFieldHandle fieldHandle);
1769 [System.Security.SecuritySafeCritical] // auto-generated
1770 internal bool IsSecurityTransparent()
1772 return IsSecurityTransparent(GetNativeHandle());
1776 [ResourceExposure(ResourceScope.None)]
1777 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1778 [SuppressUnmanagedCodeSecurity]
1779 internal static extern void CheckAttributeAccess(RuntimeFieldHandle fieldHandle, RuntimeModule decoratedTarget);
1781 // ISerializable interface
1782 [System.Security.SecurityCritical] // auto-generated
1783 private RuntimeFieldHandle(SerializationInfo info, StreamingContext context)
1786 throw new ArgumentNullException("info");
1787 Contract.EndContractBlock();
1789 FieldInfo f =(RuntimeFieldInfo) info.GetValue("FieldObj", typeof(RuntimeFieldInfo));
1792 throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
1794 m_ptr = f.FieldHandle.m_ptr;
1797 throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
1800 [System.Security.SecurityCritical]
1801 public void GetObjectData(SerializationInfo info, StreamingContext context)
1804 throw new ArgumentNullException("info");
1805 Contract.EndContractBlock();
1808 throw new SerializationException(Environment.GetResourceString("Serialization_InvalidFieldState"));
1810 RuntimeFieldInfo fldInfo = (RuntimeFieldInfo)RuntimeType.GetFieldInfo(this.GetRuntimeFieldInfo());
1812 info.AddValue("FieldObj",fldInfo, typeof(RuntimeFieldInfo));
1816 [System.Runtime.InteropServices.ComVisible(true)]
1817 public unsafe struct ModuleHandle
1819 // Returns handle for interop with EE. The handle is guaranteed to be non-null.
1820 #region Public Static Members
1821 public static readonly ModuleHandle EmptyHandle = GetEmptyMH();
1824 unsafe static private ModuleHandle GetEmptyMH()
1826 return new ModuleHandle();
1829 #region Private Data Members
1830 private RuntimeModule m_ptr;
1834 internal ModuleHandle(RuntimeModule module)
1840 #region Internal FCalls
1842 internal RuntimeModule GetRuntimeModule()
1847 internal bool IsNullHandle()
1849 return m_ptr == null;
1852 public override int GetHashCode()
1854 return m_ptr != null ? m_ptr.GetHashCode() : 0;
1857 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1858 public override bool Equals(object obj)
1860 if (!(obj is ModuleHandle))
1863 ModuleHandle handle = (ModuleHandle)obj;
1865 return handle.m_ptr == m_ptr;
1868 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1869 public unsafe bool Equals(ModuleHandle handle)
1871 return handle.m_ptr == m_ptr;
1874 public static bool operator ==(ModuleHandle left, ModuleHandle right)
1876 return left.Equals(right);
1879 public static bool operator !=(ModuleHandle left, ModuleHandle right)
1881 return !left.Equals(right);
1884 [System.Security.SecurityCritical] // auto-generated
1885 [ResourceExposure(ResourceScope.None)]
1886 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1887 internal static extern IRuntimeMethodInfo GetDynamicMethod(DynamicMethod method, RuntimeModule module, string name, byte[] sig, Resolver resolver);
1889 [System.Security.SecurityCritical] // auto-generated
1890 [ResourceExposure(ResourceScope.None)]
1891 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1892 internal static extern int GetToken(RuntimeModule module);
1894 private static void ValidateModulePointer(RuntimeModule module)
1896 // Make sure we have a valid Module to resolve against.
1898 throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullModuleHandle"));
1901 // SQL-CLR LKG9 Compiler dependency
1902 public RuntimeTypeHandle GetRuntimeTypeHandleFromMetadataToken(int typeToken) { return ResolveTypeHandle(typeToken); }
1903 public RuntimeTypeHandle ResolveTypeHandle(int typeToken)
1905 return new RuntimeTypeHandle(ResolveTypeHandleInternal(GetRuntimeModule(), typeToken, null, null));
1907 public RuntimeTypeHandle ResolveTypeHandle(int typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
1909 return new RuntimeTypeHandle(ModuleHandle.ResolveTypeHandleInternal(GetRuntimeModule(), typeToken, typeInstantiationContext, methodInstantiationContext));
1912 [System.Security.SecuritySafeCritical] // auto-generated
1913 internal static RuntimeType ResolveTypeHandleInternal(RuntimeModule module, int typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
1915 ValidateModulePointer(module);
1916 if (!ModuleHandle.GetMetadataImport(module).IsValidToken(typeToken))
1917 throw new ArgumentOutOfRangeException("metadataToken",
1918 Environment.GetResourceString("Argument_InvalidToken", typeToken, new ModuleHandle(module)));
1920 int typeInstCount, methodInstCount;
1921 IntPtr[] typeInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out typeInstCount);
1922 IntPtr[] methodInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out methodInstCount);
1924 fixed (IntPtr* typeInstArgs = typeInstantiationContextHandles, methodInstArgs = methodInstantiationContextHandles)
1926 RuntimeType type = null;
1927 ResolveType(module, typeToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount, JitHelpers.GetObjectHandleOnStack(ref type));
1928 GC.KeepAlive(typeInstantiationContext);
1929 GC.KeepAlive(methodInstantiationContext);
1934 [System.Security.SecurityCritical] // auto-generated
1935 [ResourceExposure(ResourceScope.None)]
1936 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1937 [SuppressUnmanagedCodeSecurity]
1938 private extern static void ResolveType(RuntimeModule module,
1940 IntPtr* typeInstArgs,
1942 IntPtr* methodInstArgs,
1943 int methodInstCount,
1944 ObjectHandleOnStack type);
1946 // SQL-CLR LKG9 Compiler dependency
1947 public RuntimeMethodHandle GetRuntimeMethodHandleFromMetadataToken(int methodToken) { return ResolveMethodHandle(methodToken); }
1948 public RuntimeMethodHandle ResolveMethodHandle(int methodToken) { return ResolveMethodHandle(methodToken, null, null); }
1949 internal static IRuntimeMethodInfo ResolveMethodHandleInternal(RuntimeModule module, int methodToken) { return ModuleHandle.ResolveMethodHandleInternal(module, methodToken, null, null); }
1950 public RuntimeMethodHandle ResolveMethodHandle(int methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
1952 return new RuntimeMethodHandle(ResolveMethodHandleInternal(GetRuntimeModule(), methodToken, typeInstantiationContext, methodInstantiationContext));
1955 [System.Security.SecuritySafeCritical] // auto-generated
1956 internal static IRuntimeMethodInfo ResolveMethodHandleInternal(RuntimeModule module, int methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
1958 int typeInstCount, methodInstCount;
1960 IntPtr[] typeInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out typeInstCount);
1961 IntPtr[] methodInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out methodInstCount);
1963 RuntimeMethodHandleInternal handle = ResolveMethodHandleInternalCore(module, methodToken, typeInstantiationContextHandles, typeInstCount, methodInstantiationContextHandles, methodInstCount);
1964 IRuntimeMethodInfo retVal = new RuntimeMethodInfoStub(handle, RuntimeMethodHandle.GetLoaderAllocator(handle));
1965 GC.KeepAlive(typeInstantiationContext);
1966 GC.KeepAlive(methodInstantiationContext);
1970 [System.Security.SecurityCritical] // auto-generated
1971 internal static RuntimeMethodHandleInternal ResolveMethodHandleInternalCore(RuntimeModule module, int methodToken, IntPtr[] typeInstantiationContext, int typeInstCount, IntPtr[] methodInstantiationContext, int methodInstCount)
1973 ValidateModulePointer(module);
1974 if (!ModuleHandle.GetMetadataImport(module.GetNativeHandle()).IsValidToken(methodToken))
1975 throw new ArgumentOutOfRangeException("metadataToken",
1976 Environment.GetResourceString("Argument_InvalidToken", methodToken, new ModuleHandle(module)));
1978 fixed (IntPtr* typeInstArgs = typeInstantiationContext, methodInstArgs = methodInstantiationContext)
1980 return ResolveMethod(module.GetNativeHandle(), methodToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount);
1984 [System.Security.SecurityCritical] // auto-generated
1985 [ResourceExposure(ResourceScope.None)]
1986 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1987 [SuppressUnmanagedCodeSecurity]
1988 private extern static RuntimeMethodHandleInternal ResolveMethod(RuntimeModule module,
1990 IntPtr* typeInstArgs,
1992 IntPtr* methodInstArgs,
1993 int methodInstCount);
1995 // SQL-CLR LKG9 Compiler dependency
1996 public RuntimeFieldHandle GetRuntimeFieldHandleFromMetadataToken(int fieldToken) { return ResolveFieldHandle(fieldToken); }
1997 public RuntimeFieldHandle ResolveFieldHandle(int fieldToken) { return new RuntimeFieldHandle(ResolveFieldHandleInternal(GetRuntimeModule(), fieldToken, null, null)); }
1998 public RuntimeFieldHandle ResolveFieldHandle(int fieldToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
1999 { return new RuntimeFieldHandle(ResolveFieldHandleInternal(GetRuntimeModule(), fieldToken, typeInstantiationContext, methodInstantiationContext)); }
2001 [System.Security.SecuritySafeCritical] // auto-generated
2002 internal static IRuntimeFieldInfo ResolveFieldHandleInternal(RuntimeModule module, int fieldToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
2004 ValidateModulePointer(module);
2005 if (!ModuleHandle.GetMetadataImport(module.GetNativeHandle()).IsValidToken(fieldToken))
2006 throw new ArgumentOutOfRangeException("metadataToken",
2007 Environment.GetResourceString("Argument_InvalidToken", fieldToken, new ModuleHandle(module)));
2009 // defensive copy to be sure array is not mutated from the outside during processing
2010 int typeInstCount, methodInstCount;
2011 IntPtr [] typeInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out typeInstCount);
2012 IntPtr [] methodInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out methodInstCount);
2014 fixed (IntPtr* typeInstArgs = typeInstantiationContextHandles, methodInstArgs = methodInstantiationContextHandles)
2016 IRuntimeFieldInfo field = null;
2017 ResolveField(module.GetNativeHandle(), fieldToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount, JitHelpers.GetObjectHandleOnStack(ref field));
2018 GC.KeepAlive(typeInstantiationContext);
2019 GC.KeepAlive(methodInstantiationContext);
2024 [System.Security.SecurityCritical] // auto-generated
2025 [ResourceExposure(ResourceScope.None)]
2026 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
2027 [SuppressUnmanagedCodeSecurity]
2028 private extern static void ResolveField(RuntimeModule module,
2030 IntPtr* typeInstArgs,
2032 IntPtr* methodInstArgs,
2033 int methodInstCount,
2034 ObjectHandleOnStack retField);
2036 [System.Security.SecurityCritical] // auto-generated
2037 [ResourceExposure(ResourceScope.None)]
2038 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
2039 [SuppressUnmanagedCodeSecurity]
2040 private extern static bool _ContainsPropertyMatchingHash(RuntimeModule module, int propertyToken, uint hash);
2042 [System.Security.SecurityCritical] // auto-generated
2043 internal static bool ContainsPropertyMatchingHash(RuntimeModule module, int propertyToken, uint hash)
2045 return _ContainsPropertyMatchingHash(module.GetNativeHandle(), propertyToken, hash);
2048 [System.Security.SecurityCritical] // auto-generated
2049 [ResourceExposure(ResourceScope.None)]
2050 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
2051 [SuppressUnmanagedCodeSecurity]
2052 private extern static void GetAssembly(RuntimeModule handle, ObjectHandleOnStack retAssembly);
2054 [System.Security.SecuritySafeCritical] // auto-generated
2055 internal static RuntimeAssembly GetAssembly(RuntimeModule module)
2057 RuntimeAssembly retAssembly = null;
2058 GetAssembly(module.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref retAssembly));
2062 [System.Security.SecurityCritical] // auto-generated
2063 [ResourceExposure(ResourceScope.None)]
2064 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
2065 [SuppressUnmanagedCodeSecurity]
2066 internal extern static void GetModuleType(RuntimeModule handle, ObjectHandleOnStack type);
2068 [System.Security.SecuritySafeCritical] // auto-generated
2069 internal static RuntimeType GetModuleType(RuntimeModule module)
2071 RuntimeType type = null;
2072 GetModuleType(module.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
2076 [System.Security.SecurityCritical] // auto-generated
2077 [ResourceExposure(ResourceScope.None)]
2078 [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
2079 [SuppressUnmanagedCodeSecurity]
2080 private extern static void GetPEKind(RuntimeModule handle, out int peKind, out int machine);
2082 // making this internal, used by Module.GetPEKind
2083 [System.Security.SecuritySafeCritical] // auto-generated
2084 internal static void GetPEKind(RuntimeModule module, out PortableExecutableKinds peKind, out ImageFileMachine machine)
2086 int lKind, lMachine;
2087 GetPEKind(module.GetNativeHandle(), out lKind, out lMachine);
2088 peKind = (PortableExecutableKinds)lKind;
2089 machine = (ImageFileMachine)lMachine;
2092 [System.Security.SecurityCritical] // auto-generated
2093 [MethodImplAttribute(MethodImplOptions.InternalCall)]
2094 [ResourceExposure(ResourceScope.None)]
2095 internal extern static int GetMDStreamVersion(RuntimeModule module);
2097 public int MDStreamVersion
2099 [System.Security.SecuritySafeCritical] // auto-generated
2100 get { return GetMDStreamVersion(GetRuntimeModule().GetNativeHandle()); }
2103 [System.Security.SecurityCritical] // auto-generated
2104 [ResourceExposure(ResourceScope.None)]
2105 [MethodImplAttribute(MethodImplOptions.InternalCall)]
2106 private extern static IntPtr _GetMetadataImport(RuntimeModule module);
2108 [System.Security.SecurityCritical] // auto-generated
2109 internal static MetadataImport GetMetadataImport(RuntimeModule module)
2111 return new MetadataImport(_GetMetadataImport(module.GetNativeHandle()), module);
2116 internal unsafe class Signature
2119 internal enum MdSigCallingConvention : byte
2123 ExplicitThis = 0x40,
2124 CallConvMask = 0x0F,
2141 [System.Security.SecurityCritical] // auto-generated
2142 [ResourceExposure(ResourceScope.None)]
2143 [MethodImplAttribute(MethodImplOptions.InternalCall)]
2144 private extern void GetSignature(
2145 void* pCorSig, int cCorSig,
2146 RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType);
2150 #region Private Data Members
2152 // Keep the layout in sync with SignatureNative in the VM
2154 internal RuntimeType[] m_arguments;
2155 internal RuntimeType m_declaringType;
2156 internal RuntimeType m_returnTypeORfieldType;
2157 internal object m_keepalive;
2159 internal void* m_sig;
2160 internal int m_managedCallingConventionAndArgIteratorFlags; // lowest byte is CallingConvention, upper 3 bytes are ArgIterator flags
2161 internal int m_nSizeOfArgStack;
2162 internal int m_csig;
2163 internal RuntimeMethodHandleInternal m_pMethod;
2166 #region Constructors
2167 [System.Security.SecuritySafeCritical] // auto-generated
2169 IRuntimeMethodInfo method,
2170 RuntimeType[] arguments,
2171 RuntimeType returnType,
2172 CallingConventions callingConvention)
2174 m_pMethod = method.Value;
2175 m_arguments = arguments;
2176 m_returnTypeORfieldType = returnType;
2177 m_managedCallingConventionAndArgIteratorFlags = (byte)callingConvention;
2179 GetSignature(null, 0, new RuntimeFieldHandleInternal(), method, null);
2182 [System.Security.SecuritySafeCritical] // auto-generated
2183 public Signature(IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
2185 GetSignature(null, 0, new RuntimeFieldHandleInternal(), methodHandle, declaringType);
2188 [System.Security.SecurityCritical] // auto-generated
2189 public Signature(IRuntimeFieldInfo fieldHandle, RuntimeType declaringType)
2191 GetSignature(null, 0, fieldHandle.Value, null, declaringType);
2192 GC.KeepAlive(fieldHandle);
2195 [System.Security.SecurityCritical] // auto-generated
2196 public Signature(void* pCorSig, int cCorSig, RuntimeType declaringType)
2198 GetSignature(pCorSig, cCorSig, new RuntimeFieldHandleInternal(), null, declaringType);
2202 #region Internal Members
2203 internal CallingConventions CallingConvention { get { return (CallingConventions)(byte)m_managedCallingConventionAndArgIteratorFlags; } }
2204 internal RuntimeType[] Arguments { get { return m_arguments; } }
2205 internal RuntimeType ReturnType { get { return m_returnTypeORfieldType; } }
2206 internal RuntimeType FieldType { get { return m_returnTypeORfieldType; } }
2208 [System.Security.SecuritySafeCritical]
2209 [ResourceExposure(ResourceScope.None)]
2210 [MethodImplAttribute(MethodImplOptions.InternalCall)]
2211 internal static extern bool CompareSig(Signature sig1, Signature sig2);
2213 #if FEATURE_LEGACYNETCF
2214 [System.Security.SecuritySafeCritical]
2215 [ResourceExposure(ResourceScope.None)]
2216 [MethodImplAttribute(MethodImplOptions.InternalCall)]
2217 internal static extern bool CompareSigForAppCompat(Signature left, RuntimeType typeLeft, Signature right, RuntimeType typeRight);
2220 [System.Security.SecuritySafeCritical]
2221 [ResourceExposure(ResourceScope.None)]
2222 [MethodImplAttribute(MethodImplOptions.InternalCall)]
2223 internal extern Type[] GetCustomModifiers(int position, bool required);
2228 internal abstract class Resolver
2230 internal struct CORINFO_EH_CLAUSE
2233 internal int TryOffset;
2234 internal int TryLength;
2235 internal int HandlerOffset;
2236 internal int HandlerLength;
2237 internal int ClassTokenOrFilterOffset;
2241 internal abstract RuntimeType GetJitContext(ref int securityControlFlags);
2242 internal abstract byte[] GetCodeInfo(ref int stackSize, ref int initLocals, ref int EHCount);
2243 internal abstract byte[] GetLocalsSignature();
2244 [System.Security.SecurityCritical] // takes a pointer parameter
2245 internal abstract unsafe void GetEHInfo(int EHNumber, void* exception);
2246 internal abstract unsafe byte[] GetRawEHInfo();
2248 internal abstract String GetStringLiteral(int token);
2249 [System.Security.SecurityCritical] // passes a pointer out
2250 internal abstract void ResolveToken(int token, out IntPtr typeHandle, out IntPtr methodHandle, out IntPtr fieldHandle);
2251 internal abstract byte[] ResolveSignature(int token, int fromMethod);
2253 internal abstract MethodInfo GetDynamicMethod();
2254 #if FEATURE_COMPRESSEDSTACK
2255 internal abstract CompressedStack GetSecurityContext();