Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / mscorlib / system / runtimehandles.cs
1 // ==++==
2 // 
3 //   Copyright(c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6
7 namespace System 
8 {
9     using System;
10     using System.Reflection;
11     using System.Reflection.Emit;
12     using System.Runtime;
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;
20     using System.Text;
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;
27     
28     [Serializable()]
29     [System.Runtime.InteropServices.ComVisible(true)]
30     public unsafe struct RuntimeTypeHandle : ISerializable
31     {
32         // Returns handle for interop with EE. The handle is guaranteed to be non-null.
33         internal RuntimeTypeHandle GetNativeHandle()
34         {
35             // Create local copy to avoid ----s
36             RuntimeType type = m_type;
37             if (type == null)
38                 throw new ArgumentNullException(null, Environment.GetResourceString("Arg_InvalidHandle"));
39             return new RuntimeTypeHandle(type);
40         }
41
42         // Returns type for interop with EE. The type is guaranteed to be non-null.
43         internal RuntimeType GetTypeChecked()
44         {
45             // Create local copy to avoid ----s
46             RuntimeType type = m_type;
47             if (type == null)
48                 throw new ArgumentNullException(null, Environment.GetResourceString("Arg_InvalidHandle"));
49             return type;
50         }
51
52         [System.Security.SecurityCritical]  // auto-generated
53         [ResourceExposure(ResourceScope.None)]
54         [MethodImplAttribute(MethodImplOptions.InternalCall)]
55         internal extern static bool IsInstanceOfType(RuntimeType type, Object o);
56         
57         [System.Security.SecuritySafeCritical]  // auto-generated
58         internal unsafe static Type GetTypeHelper(Type typeStart, Type[] genericArgs, IntPtr pModifiers, int cModifiers)
59         {
60             Type type = typeStart;
61
62             if (genericArgs != null)
63             {
64                 type = type.MakeGenericType(genericArgs);
65             }
66
67             if (cModifiers > 0)
68             {
69                 int* arModifiers = (int*)pModifiers.ToPointer();
70                 for(int i = 0; i < cModifiers; i++)
71                 {
72                     if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.Ptr)
73                         type = type.MakePointerType();
74                     
75                     else if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.ByRef)
76                         type = type.MakeByRefType();
77
78                     else if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.SzArray)
79                         type = type.MakeArrayType();
80
81                     else
82                         type = type.MakeArrayType(Marshal.ReadInt32((IntPtr)arModifiers, ++i * sizeof(int)));
83                 }
84             }
85             
86             return type;
87         }
88
89         public static bool operator ==(RuntimeTypeHandle left, object right) { return left.Equals(right); }
90         
91         public static bool operator ==(object left, RuntimeTypeHandle right) { return right.Equals(left); }
92         
93         public static bool operator !=(RuntimeTypeHandle left, object right) { return !left.Equals(right); }
94
95         public static bool operator !=(object left, RuntimeTypeHandle right) { return !right.Equals(left); }
96
97         internal static RuntimeTypeHandle EmptyHandle
98         {
99             get
100             {
101                 return new RuntimeTypeHandle(null);
102             }
103         }
104         
105
106         // This is the RuntimeType for the type
107         private RuntimeType m_type;
108
109         public override int GetHashCode()
110         {
111             return m_type != null ? m_type.GetHashCode() : 0;
112         }
113
114         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
115         public override bool Equals(object obj)
116         {
117             if(!(obj is RuntimeTypeHandle))
118                 return false;
119
120             RuntimeTypeHandle handle =(RuntimeTypeHandle)obj;
121             return handle.m_type == m_type;
122         }
123
124         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
125         public bool Equals(RuntimeTypeHandle handle)
126         {
127             return handle.m_type == m_type;
128         }
129
130         public IntPtr Value
131         {
132 #if !FEATURE_LEGACYNETCF
133             [SecurityCritical]
134 #endif
135             get
136             {
137                 return m_type != null ? m_type.m_handle : IntPtr.Zero;
138             }
139         }
140
141         [System.Security.SecuritySafeCritical]  // auto-generated
142         [ResourceExposure(ResourceScope.None)]
143         [MethodImpl(MethodImplOptions.InternalCall)]
144         internal static extern IntPtr GetValueInternal(RuntimeTypeHandle handle);
145
146         internal RuntimeTypeHandle(RuntimeType type)
147         {
148             m_type = type;
149         }
150
151         internal bool IsNullHandle() 
152         {
153             return m_type == null; 
154         }
155
156         [System.Security.SecuritySafeCritical]  // auto-generated
157         internal static bool IsPrimitive(RuntimeType type)
158         {
159             CorElementType corElemType = GetCorElementType(type);
160             return (corElemType >= CorElementType.Boolean && corElemType <= CorElementType.R8) ||
161                     corElemType == CorElementType.I ||
162                     corElemType == CorElementType.U;
163         }
164
165         [System.Security.SecuritySafeCritical]  // auto-generated
166         internal static bool IsByRef(RuntimeType type)
167         {
168             CorElementType corElemType = GetCorElementType(type);
169             return (corElemType == CorElementType.ByRef);
170         }
171
172         [System.Security.SecuritySafeCritical]  // auto-generated
173         internal static bool IsPointer(RuntimeType type)
174         {
175             CorElementType corElemType = GetCorElementType(type);
176             return (corElemType == CorElementType.Ptr);
177         }
178
179         [System.Security.SecuritySafeCritical]  // auto-generated
180         internal static bool IsArray(RuntimeType type)
181         {
182             CorElementType corElemType = GetCorElementType(type);
183             return (corElemType == CorElementType.Array || corElemType == CorElementType.SzArray);
184         }
185
186         [System.Security.SecuritySafeCritical]  // auto-generated
187         internal static bool IsSzArray(RuntimeType type)
188         {
189             CorElementType corElemType = GetCorElementType(type);
190             return (corElemType == CorElementType.SzArray);
191         }
192
193         [System.Security.SecuritySafeCritical]  // auto-generated
194         internal static bool HasElementType(RuntimeType type)
195         {
196             CorElementType corElemType = GetCorElementType(type);
197
198             return ((corElemType == CorElementType.Array || corElemType == CorElementType.SzArray) // IsArray
199                    || (corElemType == CorElementType.Ptr)                                          // IsPointer
200                    || (corElemType == CorElementType.ByRef));                                      // IsByRef
201         }
202
203         [SecurityCritical]
204         internal static IntPtr[] CopyRuntimeTypeHandles(RuntimeTypeHandle[] inHandles, out int length)
205         {
206             if (inHandles == null || inHandles.Length == 0)
207             {
208                 length = 0;
209                 return null;
210             }
211
212             IntPtr[] outHandles = new IntPtr[inHandles.Length];
213             for (int i = 0; i < inHandles.Length; i++)
214             {
215                 outHandles[i] = inHandles[i].Value;
216             }
217             length = outHandles.Length;
218             return outHandles;
219         }
220
221         [SecurityCritical]
222         internal static IntPtr[] CopyRuntimeTypeHandles(Type[] inHandles, out int length)
223         {
224             if (inHandles == null || inHandles.Length == 0)
225             {
226                 length = 0;
227                 return null;
228             }
229
230             IntPtr[] outHandles = new IntPtr[inHandles.Length];
231             for (int i = 0; i < inHandles.Length; i++)
232             {
233                 outHandles[i] = inHandles[i].GetTypeHandleInternal().Value;
234             }
235             length = outHandles.Length;
236             return outHandles;
237         }
238
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);
243
244         [System.Security.SecurityCritical]  // auto-generated
245         [ResourceExposure(ResourceScope.None)]
246         [MethodImplAttribute(MethodImplOptions.InternalCall)]
247         internal static extern Object CreateCaInstance(RuntimeType type, IRuntimeMethodInfo ctor);
248
249         [System.Security.SecurityCritical]  // auto-generated
250         [ResourceExposure(ResourceScope.None)]
251         [MethodImplAttribute(MethodImplOptions.InternalCall)]
252         internal static extern Object Allocate(RuntimeType type);
253
254         [System.Security.SecurityCritical]  // auto-generated
255         [ResourceExposure(ResourceScope.None)]
256         [MethodImplAttribute(MethodImplOptions.InternalCall)]
257         internal static extern Object CreateInstanceForAnotherGenericParameter(RuntimeType type, RuntimeType genericParameter);
258         
259         internal RuntimeType GetRuntimeType()
260         {
261             return m_type;
262         }
263
264         [System.Security.SecurityCritical]  // auto-generated
265         [ResourceExposure(ResourceScope.None)]
266         [MethodImplAttribute(MethodImplOptions.InternalCall)]
267         internal extern static CorElementType GetCorElementType(RuntimeType type);
268
269         [System.Security.SecuritySafeCritical]  // auto-generated
270         [ResourceExposure(ResourceScope.None)]
271         [MethodImplAttribute(MethodImplOptions.InternalCall)]
272         internal extern static RuntimeAssembly GetAssembly(RuntimeType type);
273
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);
279
280         [CLSCompliant(false)]
281         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
282         public ModuleHandle GetModuleHandle()
283         {
284             return new ModuleHandle(RuntimeTypeHandle.GetModule(m_type));
285         }
286         
287         [System.Security.SecuritySafeCritical]
288         [ResourceExposure(ResourceScope.None)]
289         [MethodImplAttribute(MethodImplOptions.InternalCall)]
290         internal extern static RuntimeType GetBaseType(RuntimeType type);
291
292         [System.Security.SecurityCritical]  // auto-generated
293         [ResourceExposure(ResourceScope.None)]
294         [MethodImplAttribute(MethodImplOptions.InternalCall)]
295         internal extern static TypeAttributes GetAttributes(RuntimeType type); 
296
297         [System.Security.SecuritySafeCritical]  // auto-generated
298         [ResourceExposure(ResourceScope.None)]
299         [MethodImplAttribute(MethodImplOptions.InternalCall)]
300         internal extern static RuntimeType GetElementType(RuntimeType type);
301
302         [System.Security.SecurityCritical]  // auto-generated
303         [ResourceExposure(ResourceScope.None)]
304         [MethodImplAttribute(MethodImplOptions.InternalCall)]
305         internal extern static bool CompareCanonicalHandles(RuntimeType left, RuntimeType right);
306
307         [System.Security.SecurityCritical]  // auto-generated
308         [ResourceExposure(ResourceScope.None)]
309         [MethodImplAttribute(MethodImplOptions.InternalCall)]
310         internal extern static int GetArrayRank(RuntimeType type); 
311
312         [System.Security.SecurityCritical]  // auto-generated
313         [ResourceExposure(ResourceScope.None)]
314         [MethodImplAttribute(MethodImplOptions.InternalCall)]
315         internal extern static int GetToken(RuntimeType type); 
316         
317         [System.Security.SecuritySafeCritical]  // auto-generated
318         [ResourceExposure(ResourceScope.None)]
319         [MethodImplAttribute(MethodImplOptions.InternalCall)]
320         internal extern static RuntimeMethodHandleInternal GetMethodAt(RuntimeType type, int slot);
321
322         // This is managed wrapper for MethodTable::IntroducedMethodIterator
323         internal struct IntroducedMethodEnumerator
324         {
325             bool                    _firstCall;
326             RuntimeMethodHandleInternal _handle;
327
328             [System.Security.SecuritySafeCritical]  // auto-generated
329             internal IntroducedMethodEnumerator(RuntimeType type)
330             {
331                 _handle = RuntimeTypeHandle.GetFirstIntroducedMethod(type);
332                 _firstCall = true;
333             }
334         
335             [System.Security.SecuritySafeCritical]  // auto-generated
336             public bool MoveNext() 
337             {
338                 if (_firstCall)
339                 {
340                     _firstCall = false;
341                 }
342                 else if (_handle.Value != IntPtr.Zero)
343                 {
344                     RuntimeTypeHandle.GetNextIntroducedMethod(ref _handle);
345                 }
346                 return !(_handle.Value == IntPtr.Zero);
347             }
348
349             public RuntimeMethodHandleInternal Current
350             { 
351                 get {
352                     return _handle;
353                 }
354             }
355
356             // Glue to make this work nicely with C# foreach statement
357             public IntroducedMethodEnumerator GetEnumerator()
358             {
359                 return this;
360             }
361         }
362
363         internal static IntroducedMethodEnumerator GetIntroducedMethods(RuntimeType type)
364         {
365             return new IntroducedMethodEnumerator(type);
366         }
367
368         [System.Security.SecurityCritical]  // auto-generated
369         [ResourceExposure(ResourceScope.None)]
370         [MethodImplAttribute(MethodImplOptions.InternalCall)]
371         private static extern RuntimeMethodHandleInternal GetFirstIntroducedMethod(RuntimeType type);
372
373         [System.Security.SecurityCritical]  // auto-generated
374         [ResourceExposure(ResourceScope.None)]
375         [MethodImplAttribute(MethodImplOptions.InternalCall)]
376         private static extern void GetNextIntroducedMethod(ref RuntimeMethodHandleInternal method);
377         
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);
382         
383         [System.Security.SecurityCritical]  // auto-generated
384         [ResourceExposure(ResourceScope.AppDomain)]
385         [MethodImplAttribute(MethodImplOptions.InternalCall)]
386         internal extern static Type[] GetInterfaces(RuntimeType type);
387         
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);
393
394         [System.Security.SecuritySafeCritical]  // auto-generated
395         internal Type[] GetConstraints()
396         {
397             Type[] types = null;
398             GetConstraints(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types));
399
400             return types;
401         }
402
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);
408
409         [System.Security.SecurityCritical]  // auto-generated
410         internal IntPtr GetGCHandle(GCHandleType type)
411         {
412             return GetGCHandle(GetNativeHandle(), type);
413         }
414
415         [System.Security.SecurityCritical]  // auto-generated
416         [ResourceExposure(ResourceScope.None)]
417         [MethodImplAttribute(MethodImplOptions.InternalCall)]
418         internal extern static int GetNumVirtuals(RuntimeType type); 
419
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);
425
426         [System.Security.SecuritySafeCritical]  // auto-generated
427         internal void VerifyInterfaceIsImplemented(RuntimeTypeHandle interfaceHandle)
428         {
429             VerifyInterfaceIsImplemented(GetNativeHandle(), interfaceHandle.GetNativeHandle());
430         }
431
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);
437
438         [System.Security.SecuritySafeCritical]  // auto-generated
439         [ResourceExposure(ResourceScope.None)]
440         [ResourceConsumption(ResourceScope.AppDomain, ResourceScope.AppDomain)]
441         internal int GetInterfaceMethodImplementationSlot(RuntimeTypeHandle interfaceHandle, RuntimeMethodHandleInternal interfaceMethodHandle)
442         {
443             return GetInterfaceMethodImplementationSlot(GetNativeHandle(), interfaceHandle.GetNativeHandle(), interfaceMethodHandle);
444         }
445
446         [System.Security.SecurityCritical]  // auto-generated
447         [ResourceExposure(ResourceScope.None)]
448         [MethodImplAttribute(MethodImplOptions.InternalCall)]
449         internal extern static bool IsComObject(RuntimeType type, bool isGenericCOM); 
450
451         [System.Security.SecurityCritical]  // auto-generated
452         [ResourceExposure(ResourceScope.None)]
453         [MethodImplAttribute(MethodImplOptions.InternalCall)]
454         internal extern static bool IsContextful(RuntimeType type); 
455
456         [System.Security.SecurityCritical]  // auto-generated
457         [ResourceExposure(ResourceScope.None)]
458         [MethodImplAttribute(MethodImplOptions.InternalCall)]
459         internal extern static bool IsInterface(RuntimeType type);
460
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);
467         
468         [System.Security.SecuritySafeCritical]  // auto-generated
469         internal static bool IsVisible(RuntimeType type)
470         {
471             return _IsVisible(new RuntimeTypeHandle(type));
472         }
473
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);
480
481         [System.Security.SecuritySafeCritical]  // auto-generated
482         internal bool IsSecurityCritical()
483         {
484             return IsSecurityCritical(GetNativeHandle());
485         }
486
487
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);
494
495         [System.Security.SecuritySafeCritical]  // auto-generated
496         internal bool IsSecuritySafeCritical()
497         {
498             return IsSecuritySafeCritical(GetNativeHandle());
499         }
500
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);
507
508         [System.Security.SecuritySafeCritical]  // auto-generated
509         internal bool IsSecurityTransparent()
510         {
511             return IsSecurityTransparent(GetNativeHandle());
512         }
513
514         [System.Security.SecurityCritical]  // auto-generated
515         [ResourceExposure(ResourceScope.None)]
516         [MethodImplAttribute(MethodImplOptions.InternalCall)]
517         internal extern static bool HasProxyAttribute(RuntimeType type);
518
519         [System.Security.SecuritySafeCritical]
520         [ResourceExposure(ResourceScope.None)]
521         [MethodImplAttribute(MethodImplOptions.InternalCall)]
522         internal extern static bool IsValueType(RuntimeType type);
523
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);
529
530         [System.Security.SecuritySafeCritical]  // auto-generated
531         internal string ConstructName(TypeNameFormatFlags formatFlags)
532         {
533             string name = null;
534             ConstructName(GetNativeHandle(), formatFlags, JitHelpers.GetStringHandleOnStack(ref name));
535             return name;
536         }
537
538         [System.Security.SecurityCritical]  // auto-generated
539         [ResourceExposure(ResourceScope.None)]
540         [MethodImplAttribute(MethodImplOptions.InternalCall)]
541         private extern static void* _GetUtf8Name(RuntimeType type);
542
543         [System.Security.SecuritySafeCritical]  // auto-generated
544         internal static Utf8String GetUtf8Name(RuntimeType type)
545         {
546             return new Utf8String(_GetUtf8Name(type));
547         }
548
549         [System.Security.SecuritySafeCritical]  // auto-generated
550         [ResourceExposure(ResourceScope.None)]
551         [MethodImplAttribute(MethodImplOptions.InternalCall)]
552         internal extern static bool CanCastTo(RuntimeType type, RuntimeType target);
553
554         [System.Security.SecurityCritical]  // auto-generated
555         [ResourceExposure(ResourceScope.None)]
556         [MethodImplAttribute(MethodImplOptions.InternalCall)]
557         internal extern static RuntimeType GetDeclaringType(RuntimeType type);
558         
559         [System.Security.SecuritySafeCritical]  // auto-generated
560         [ResourceExposure(ResourceScope.None)]
561         [MethodImplAttribute(MethodImplOptions.InternalCall)]
562         internal extern static IRuntimeMethodInfo GetDeclaringMethod(RuntimeType type);
563         
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);
569
570         [System.Security.SecuritySafeCritical]  // auto-generated
571         internal IRuntimeMethodInfo GetDefaultConstructor()       
572         {
573             IRuntimeMethodInfo ctor = null;
574             GetDefaultConstructor(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref ctor));
575             return ctor;
576         }
577        
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,
585 #endif
586             bool loadTypeFromPartialName, ObjectHandleOnStack type);
587
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)
591         {
592             return GetTypeByName(name, throwOnError, ignoreCase, reflectionOnly, ref stackMark, IntPtr.Zero, loadTypeFromPartialName);
593         }
594 #endif
595
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,
600 #endif
601                                                   bool loadTypeFromPartialName)
602         {
603             if (name == null || name.Length == 0)
604             {
605                 if (throwOnError)
606                     throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr"));
607
608                 return null;
609             }
610
611             RuntimeType type = null;
612
613             GetTypeByName(name, throwOnError, ignoreCase, reflectionOnly,
614                 JitHelpers.GetStackCrawlMarkHandle(ref stackMark),
615 #if FEATURE_HOSTED_BINDER
616                 pPrivHostBinder,
617 #endif
618                 loadTypeFromPartialName, JitHelpers.GetObjectHandleOnStack(ref type));
619
620             return type;
621         }
622
623         internal static Type GetTypeByName(string name, ref StackCrawlMark stackMark)
624         {
625             return GetTypeByName(name, false, false, false, ref stackMark, false);
626         }
627
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);
633
634         [System.Security.SecuritySafeCritical]  // auto-generated
635         internal static RuntimeType GetTypeByNameUsingCARules(string name, RuntimeModule scope)
636         {
637             if (name == null || name.Length == 0)
638                 throw new ArgumentException("name"); 
639             Contract.EndContractBlock();
640
641             RuntimeType type = null;
642             GetTypeByNameUsingCARules(name, scope.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
643
644             return type;
645         }
646
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);
652
653         [System.Security.SecuritySafeCritical]  // auto-generated
654         internal RuntimeType[] GetInstantiationInternal()
655         {
656             RuntimeType[] types = null;
657             GetInstantiation(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types), true);
658             return types;
659         }
660
661         [System.Security.SecuritySafeCritical]  // auto-generated
662         internal Type[] GetInstantiationPublic()
663         {
664             Type[] types = null;
665             GetInstantiation(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types), false);
666             return types;
667         }
668
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);
674
675         [System.Security.SecurityCritical]  // auto-generated
676         internal RuntimeType Instantiate(Type[] inst)
677         {
678             // defensive copy to be sure array is not mutated from the outside during processing
679             int instCount;
680             IntPtr []instHandles = CopyRuntimeTypeHandles(inst, out instCount);
681
682             fixed (IntPtr* pInst = instHandles)
683             {
684                 RuntimeType type = null;
685                 Instantiate(GetNativeHandle(), pInst, instCount, JitHelpers.GetObjectHandleOnStack(ref type));
686                 GC.KeepAlive(inst);
687                 return type;
688             }
689         }
690
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);
696
697         [System.Security.SecuritySafeCritical]  // auto-generated
698         internal RuntimeType MakeArray(int rank)
699         {
700             RuntimeType type = null;
701             MakeArray(GetNativeHandle(), rank, JitHelpers.GetObjectHandleOnStack(ref type));
702             return type;
703         }
704
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);
710
711         [System.Security.SecuritySafeCritical]  // auto-generated
712         internal RuntimeType MakeSZArray()
713         {
714             RuntimeType type = null;
715             MakeSZArray(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
716             return type;
717         }
718         
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);
724
725         [System.Security.SecuritySafeCritical]  // auto-generated
726         internal RuntimeType MakeByRef()
727         {
728 #if FEATURE_LEGACYNETCF
729             try {
730 #endif
731                 RuntimeType type = null;
732                 MakeByRef(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
733                 return type;
734 #if FEATURE_LEGACYNETCF
735             } catch(Exception) {
736                 if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
737                     return null;
738                 throw;
739             }
740 #endif
741         }
742        
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);
748
749         [System.Security.SecurityCritical]  // auto-generated
750         internal RuntimeType MakePointer()
751         {
752             RuntimeType type = null;
753             MakePointer(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
754             return type;
755         }
756
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);
762         
763         #if FEATURE_CORECLR
764         [System.Security.SecuritySafeCritical] // auto-generated
765         #endif
766         [ResourceExposure(ResourceScope.None)]
767         [MethodImplAttribute(MethodImplOptions.InternalCall)]
768         internal extern static bool HasInstantiation(RuntimeType type);
769
770         internal bool HasInstantiation()
771         {
772             return HasInstantiation(GetTypeChecked());
773         }
774
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);
780
781         [System.Security.SecuritySafeCritical]  // auto-generated
782         internal static RuntimeType GetGenericTypeDefinition(RuntimeType type)
783         {
784             RuntimeType retType = type;
785
786             if (HasInstantiation(retType) && !IsGenericTypeDefinition(retType))
787                 GetGenericTypeDefinition(retType.GetTypeHandleInternal(), JitHelpers.GetObjectHandleOnStack(ref retType));
788
789             return retType;
790         }
791
792         [System.Security.SecuritySafeCritical]  // auto-generated
793         [ResourceExposure(ResourceScope.None)]
794         [MethodImplAttribute(MethodImplOptions.InternalCall)]
795         internal extern static bool IsGenericTypeDefinition(RuntimeType type);
796        
797         [System.Security.SecuritySafeCritical]  // auto-generated
798         [ResourceExposure(ResourceScope.None)]
799         [MethodImplAttribute(MethodImplOptions.InternalCall)]
800         internal extern static bool IsGenericVariable(RuntimeType type);
801
802         internal bool IsGenericVariable()
803         {
804             return IsGenericVariable(GetTypeChecked());
805         }
806
807         [System.Security.SecurityCritical]  // auto-generated
808         [ResourceExposure(ResourceScope.None)]
809         [MethodImplAttribute(MethodImplOptions.InternalCall)]
810         private extern static int GetGenericVariableIndex(RuntimeType type);
811
812         [System.Security.SecuritySafeCritical]  // auto-generated
813         internal int GetGenericVariableIndex()
814         {
815             RuntimeType type = GetTypeChecked();
816
817             if (!IsGenericVariable(type))
818                 throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericParameter"));
819
820             return GetGenericVariableIndex(type);
821         }
822
823         [System.Security.SecurityCritical]  // auto-generated
824         [ResourceExposure(ResourceScope.None)]
825         [MethodImplAttribute(MethodImplOptions.InternalCall)]
826         internal extern static bool ContainsGenericVariables(RuntimeType handle);
827
828         [System.Security.SecuritySafeCritical]  // auto-generated
829         internal bool ContainsGenericVariables()
830         {
831             return ContainsGenericVariables(GetTypeChecked());
832         }
833         
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);
838
839         [System.Security.SecurityCritical]
840         internal static bool SatisfiesConstraints(RuntimeType paramType, RuntimeType[] typeContext, RuntimeType[] methodContext, RuntimeType toType)
841         {
842             int typeContextLength;
843             int methodContextLength;
844             IntPtr[] typeContextHandles = CopyRuntimeTypeHandles(typeContext, out typeContextLength);
845             IntPtr[] methodContextHandles = CopyRuntimeTypeHandles(methodContext, out methodContextLength);
846             
847             fixed (IntPtr *pTypeContextHandles = typeContextHandles, pMethodContextHandles = methodContextHandles)
848             {
849                 bool result = SatisfiesConstraints(paramType, pTypeContextHandles, typeContextLength, pMethodContextHandles, methodContextLength, toType);
850
851                 GC.KeepAlive(typeContext);
852                 GC.KeepAlive(methodContext);
853
854                 return result;
855             }
856         }
857
858         [System.Security.SecurityCritical]  // auto-generated
859         [ResourceExposure(ResourceScope.None)]
860         [MethodImplAttribute(MethodImplOptions.InternalCall)]
861         private extern static IntPtr _GetMetadataImport(RuntimeType type);
862
863         [System.Security.SecurityCritical]  // auto-generated
864         internal static MetadataImport GetMetadataImport(RuntimeType type)
865         {
866             return new MetadataImport(_GetMetadataImport(type), type);
867         }
868         
869         [System.Security.SecurityCritical]  // auto-generated
870         private RuntimeTypeHandle(SerializationInfo info, StreamingContext context)
871         {
872             if(info == null) 
873                 throw new ArgumentNullException("info");
874             Contract.EndContractBlock();
875
876             RuntimeType m = (RuntimeType)info.GetValue("TypeObj", typeof(RuntimeType));
877
878             m_type = m;
879
880             if (m_type == null)
881                 throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
882         }
883
884         [System.Security.SecurityCritical]
885         public void GetObjectData(SerializationInfo info, StreamingContext context) 
886         {
887             if(info == null) 
888                 throw new ArgumentNullException("info");
889             Contract.EndContractBlock();
890
891             if (m_type == null)
892                 throw new SerializationException(Environment.GetResourceString("Serialization_InvalidFieldState")); 
893
894             info.AddValue("TypeObj", m_type, typeof(RuntimeType));
895         }
896
897 #if !FEATURE_CORECLR
898         [System.Security.SecuritySafeCritical]
899         [ResourceExposure(ResourceScope.None)]
900         [MethodImpl(MethodImplOptions.InternalCall)]
901         internal static extern bool IsEquivalentTo(RuntimeType rtType1, RuntimeType rtType2);
902
903         [System.Security.SecuritySafeCritical]
904         [ResourceExposure(ResourceScope.None)]
905         [MethodImpl(MethodImplOptions.InternalCall)]
906         internal static extern bool IsEquivalentType(RuntimeType type);
907 #endif // FEATURE_CORECLR
908     }
909
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
920     {
921         internal static RuntimeMethodHandleInternal EmptyHandle
922         {
923             get
924             {
925                 return new RuntimeMethodHandleInternal();
926             }
927         }
928
929         internal bool IsNullHandle()
930         {
931             return m_handle.IsNull();
932         }
933
934         internal IntPtr Value
935         {
936             [SecurityCritical]
937             get
938             {
939                 return m_handle;
940             }
941         }
942
943         [SecurityCritical]
944         internal RuntimeMethodHandleInternal(IntPtr value)
945         {
946             m_handle = value;
947         }
948       
949         internal IntPtr m_handle;
950     }
951
952     internal class RuntimeMethodInfoStub : IRuntimeMethodInfo
953     {
954         public RuntimeMethodInfoStub(RuntimeMethodHandleInternal methodHandleValue, object keepalive)
955         {
956             m_keepalive = keepalive;
957             m_value = methodHandleValue;
958         }
959
960         [SecurityCritical]
961         public RuntimeMethodInfoStub(IntPtr methodHandleValue, object keepalive)
962         {
963             m_keepalive = keepalive;
964             m_value = new RuntimeMethodHandleInternal(methodHandleValue);
965         }
966
967         object m_keepalive;
968
969         // These unused variables are used to ensure that this class has the same layout as RuntimeMethodInfo
970 #pragma warning disable 169
971         object m_a;
972         object m_b;
973         object m_c;
974         object m_d;
975         object m_e;
976         object m_f;
977         object m_g;
978 #if FEATURE_REMOTING
979         object m_h;
980 #endif
981 #pragma warning restore 169
982         public RuntimeMethodHandleInternal m_value;
983
984         RuntimeMethodHandleInternal IRuntimeMethodInfo.Value
985         {
986             get
987             {
988                 return m_value;
989             }
990         }
991     }
992
993     internal interface IRuntimeMethodInfo
994     {
995         RuntimeMethodHandleInternal Value
996         {
997             get;
998         }
999     }                                       
1000
1001     [Serializable]
1002 [System.Runtime.InteropServices.ComVisible(true)]
1003     public unsafe struct RuntimeMethodHandle : ISerializable
1004     {
1005         // Returns handle for interop with EE. The handle is guaranteed to be non-null.
1006         internal static IRuntimeMethodInfo EnsureNonNullMethodInfo(IRuntimeMethodInfo method)
1007         {
1008             if (method == null)
1009                 throw new ArgumentNullException(null, Environment.GetResourceString("Arg_InvalidHandle"));
1010             return method;
1011         }
1012
1013         internal static RuntimeMethodHandle EmptyHandle
1014         {
1015             get { return new RuntimeMethodHandle(); }
1016         }
1017
1018         private IRuntimeMethodInfo m_value;
1019         
1020         internal RuntimeMethodHandle(IRuntimeMethodInfo method)
1021         {
1022             m_value = method;
1023         }
1024
1025         internal IRuntimeMethodInfo GetMethodInfo()
1026         {
1027             return m_value;
1028         }
1029
1030         // Used by EE
1031         [SecurityCritical]
1032         private static IntPtr GetValueInternal(RuntimeMethodHandle rmh)
1033         {
1034             return rmh.Value;
1035         }
1036         
1037         // ISerializable interface
1038         [System.Security.SecurityCritical]  // auto-generated
1039         private RuntimeMethodHandle(SerializationInfo info, StreamingContext context)
1040         {
1041             if(info == null)
1042                 throw new ArgumentNullException("info");
1043             Contract.EndContractBlock();
1044             
1045             MethodBase m =(MethodBase)info.GetValue("MethodObj", typeof(MethodBase));
1046
1047             m_value = m.MethodHandle.m_value;
1048
1049             if (m_value == null)
1050                 throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
1051         }
1052
1053         [System.Security.SecurityCritical]
1054         public void GetObjectData(SerializationInfo info, StreamingContext context) 
1055         {
1056             if (info == null) 
1057                 throw new ArgumentNullException("info");
1058             Contract.EndContractBlock();
1059
1060             if (m_value == null)
1061                 throw new SerializationException(Environment.GetResourceString("Serialization_InvalidFieldState"));
1062             
1063             // This is either a RuntimeMethodInfo or a RuntimeConstructorInfo
1064             MethodBase methodInfo = RuntimeType.GetMethodBase(m_value);
1065
1066             info.AddValue("MethodObj", methodInfo, typeof(MethodBase));
1067         }
1068
1069         public IntPtr Value
1070         {
1071 #if FEATURE_LEGACYNETCF
1072             [SecuritySafeCritical]
1073 #else
1074             [SecurityCritical]
1075 #endif
1076             get
1077             {
1078                 return m_value != null ? m_value.Value.Value : IntPtr.Zero;
1079             }
1080         }
1081
1082         [SecuritySafeCritical]
1083         public override int GetHashCode()
1084         {
1085             return ValueType.GetHashCodeOfPtr(Value);
1086         }
1087
1088         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1089         [SecuritySafeCritical]
1090         public override bool Equals(object obj)
1091         {
1092             if (!(obj is RuntimeMethodHandle))
1093                 return false;
1094
1095             RuntimeMethodHandle handle = (RuntimeMethodHandle)obj;
1096
1097             return handle.Value == Value;
1098         }
1099
1100         public static bool operator ==(RuntimeMethodHandle left, RuntimeMethodHandle right)
1101         {
1102             return left.Equals(right);
1103         }
1104
1105         public static bool operator !=(RuntimeMethodHandle left, RuntimeMethodHandle right)
1106         {
1107             return !left.Equals(right);
1108         }
1109
1110         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1111         [SecuritySafeCritical]
1112         public bool Equals(RuntimeMethodHandle handle)
1113         {
1114             return handle.Value == Value;
1115         }
1116
1117         [Pure]
1118         internal bool IsNullHandle() 
1119         { 
1120             return m_value == null; 
1121         }
1122
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);
1128
1129         [System.Security.SecurityCritical]  // auto-generated
1130         public IntPtr GetFunctionPointer()
1131         {
1132             IntPtr ptr = GetFunctionPointer(EnsureNonNullMethodInfo(m_value).Value);
1133             GC.KeepAlive(m_value);
1134             return ptr;
1135         }
1136
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);
1141
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);
1151
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)
1158         {
1159             return _GetCurrentMethod(ref stackMark);
1160         }
1161         
1162         [Pure]
1163         [System.Security.SecurityCritical]  // auto-generated
1164         [ResourceExposure(ResourceScope.None)]
1165         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1166         internal static extern MethodAttributes GetAttributes(RuntimeMethodHandleInternal method);
1167
1168         [System.Security.SecurityCritical]  // auto-generated
1169         internal static MethodAttributes GetAttributes(IRuntimeMethodInfo method)
1170         {
1171             MethodAttributes retVal = RuntimeMethodHandle.GetAttributes(method.Value);
1172             GC.KeepAlive(method);
1173             return retVal;
1174         }
1175
1176         [System.Security.SecuritySafeCritical]  // auto-generated
1177         [ResourceExposure(ResourceScope.None)]
1178         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1179         internal static extern MethodImplAttributes GetImplAttributes(IRuntimeMethodInfo method);
1180         
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);
1186
1187         [System.Security.SecuritySafeCritical]  // auto-generated
1188         internal static string ConstructInstantiation(IRuntimeMethodInfo method, TypeNameFormatFlags format)
1189         {
1190             string name = null;
1191             ConstructInstantiation(EnsureNonNullMethodInfo(method), format, JitHelpers.GetStringHandleOnStack(ref name));
1192             return name;
1193         }
1194
1195         [System.Security.SecurityCritical]  // auto-generated
1196         [ResourceExposure(ResourceScope.None)]
1197         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1198         internal extern static RuntimeType GetDeclaringType(RuntimeMethodHandleInternal method);
1199
1200         [System.Security.SecuritySafeCritical]  // auto-generated
1201         internal static RuntimeType GetDeclaringType(IRuntimeMethodInfo method)
1202         {
1203             RuntimeType type = RuntimeMethodHandle.GetDeclaringType(method.Value);
1204             GC.KeepAlive(method);
1205             return type;
1206         }
1207
1208         [System.Security.SecurityCritical]  // auto-generated
1209         [ResourceExposure(ResourceScope.None)]
1210         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1211         internal extern static int GetSlot(RuntimeMethodHandleInternal method);
1212
1213         [System.Security.SecurityCritical]  // auto-generated
1214         internal static int GetSlot(IRuntimeMethodInfo method)
1215         {
1216             Contract.Requires(method != null);
1217
1218             int slot = RuntimeMethodHandle.GetSlot(method.Value);
1219             GC.KeepAlive(method);
1220             return slot;
1221         }
1222         
1223         [System.Security.SecurityCritical]  // auto-generated
1224         [ResourceExposure(ResourceScope.None)]
1225         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1226         internal extern static int GetMethodDef(IRuntimeMethodInfo method);
1227
1228         [System.Security.SecurityCritical]  // auto-generated
1229         [ResourceExposure(ResourceScope.None)]
1230         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1231         internal extern static string GetName(RuntimeMethodHandleInternal method);
1232
1233         [System.Security.SecurityCritical]  // auto-generated
1234         internal static string GetName(IRuntimeMethodInfo method)
1235         {
1236             string name = RuntimeMethodHandle.GetName(method.Value);
1237             GC.KeepAlive(method);
1238             return name;
1239         }
1240
1241         [System.Security.SecurityCritical]  // auto-generated
1242         [ResourceExposure(ResourceScope.None)]
1243         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1244         private extern static void* _GetUtf8Name(RuntimeMethodHandleInternal method);
1245
1246         [System.Security.SecurityCritical]  // auto-generated
1247         internal static Utf8String GetUtf8Name(RuntimeMethodHandleInternal method)
1248         {
1249             return new Utf8String(_GetUtf8Name(method));
1250         }
1251
1252         [System.Security.SecurityCritical]  // auto-generated
1253         [ResourceExposure(ResourceScope.None)]
1254         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1255         internal static extern bool MatchesNameHash(RuntimeMethodHandleInternal method, uint hash);
1256
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);
1263
1264         #region Private Invocation Helpers
1265         [System.Security.SecurityCritical]  // auto-generated
1266         internal static INVOCATION_FLAGS GetSecurityFlags(IRuntimeMethodInfo handle)
1267         {
1268             return (INVOCATION_FLAGS)RuntimeMethodHandle.GetSpecialSecurityFlags(handle);
1269         }
1270
1271         [System.Security.SecurityCritical]  // auto-generated
1272         [ResourceExposure(ResourceScope.None)]
1273         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1274         static extern internal uint GetSpecialSecurityFlags(IRuntimeMethodInfo method);
1275
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);
1280
1281         [System.Security.SecurityCritical]
1282         static internal void PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, uint invocationFlags)
1283         {
1284             RuntimeMethodHandle.PerformSecurityCheck(obj, method.Value, parent, invocationFlags);
1285             GC.KeepAlive(method);
1286             return;
1287         }
1288         #endregion
1289
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);
1297
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);
1303         
1304         #if FEATURE_CORECLR
1305         [System.Security.SecuritySafeCritical] // auto-generated
1306         #else
1307         [System.Security.SecurityCritical]
1308         #endif
1309         internal static bool IsTokenSecurityTransparent(Module module, int metaDataToken)
1310         {
1311             return _IsTokenSecurityTransparent(module.ModuleHandle.GetRuntimeModule(), metaDataToken);
1312         }
1313
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);
1320
1321         [System.Security.SecuritySafeCritical]  // auto-generated
1322         internal static bool IsSecurityCritical(IRuntimeMethodInfo method)
1323         {
1324             return _IsSecurityCritical(method);
1325         }
1326
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);
1333
1334         [System.Security.SecuritySafeCritical]  // auto-generated
1335         internal static bool IsSecuritySafeCritical(IRuntimeMethodInfo method)
1336         {
1337             return _IsSecuritySafeCritical(method);
1338         }
1339
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);
1346
1347         [System.Security.SecuritySafeCritical]  // auto-generated
1348         internal static bool IsSecurityTransparent(IRuntimeMethodInfo method)
1349         {
1350             return _IsSecurityTransparent(method);
1351         }
1352
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);
1358
1359         [System.Security.SecuritySafeCritical]  // auto-generated
1360         internal static RuntimeType[] GetMethodInstantiationInternal(IRuntimeMethodInfo method)
1361         {
1362             RuntimeType[] types = null;
1363             GetMethodInstantiation(EnsureNonNullMethodInfo(method).Value, JitHelpers.GetObjectHandleOnStack(ref types), true);
1364             GC.KeepAlive(method);
1365             return types;
1366         }
1367
1368         [System.Security.SecuritySafeCritical]  // auto-generated
1369         internal static RuntimeType[] GetMethodInstantiationInternal(RuntimeMethodHandleInternal method)
1370         {
1371             RuntimeType[] types = null;
1372             GetMethodInstantiation(method, JitHelpers.GetObjectHandleOnStack(ref types), true);
1373             return types;
1374         }
1375
1376         [System.Security.SecuritySafeCritical]  // auto-generated
1377         internal static Type[] GetMethodInstantiationPublic(IRuntimeMethodInfo method)
1378         {
1379             RuntimeType[] types = null;
1380             GetMethodInstantiation(EnsureNonNullMethodInfo(method).Value, JitHelpers.GetObjectHandleOnStack(ref types), false);
1381             GC.KeepAlive(method);
1382             return types;
1383         }
1384
1385         [System.Security.SecurityCritical]  // auto-generated
1386         [ResourceExposure(ResourceScope.None)]
1387         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1388         internal extern static bool HasMethodInstantiation(RuntimeMethodHandleInternal method);
1389
1390         [System.Security.SecuritySafeCritical]  // auto-generated
1391         internal static bool HasMethodInstantiation(IRuntimeMethodInfo method)
1392         {
1393             bool fRet = RuntimeMethodHandle.HasMethodInstantiation(method.Value);
1394             GC.KeepAlive(method);
1395             return fRet;
1396         }
1397
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);
1402         
1403         [System.Security.SecurityCritical]  // auto-generated
1404         [ResourceExposure(ResourceScope.None)]
1405         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1406         internal extern static RuntimeMethodHandleInternal GetMethodFromCanonical(RuntimeMethodHandleInternal method, RuntimeType declaringType);
1407         
1408         [System.Security.SecurityCritical]  // auto-generated
1409         [ResourceExposure(ResourceScope.None)]
1410         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1411         internal extern static bool IsGenericMethodDefinition(RuntimeMethodHandleInternal method);
1412
1413         [System.Security.SecuritySafeCritical]  // auto-generated
1414         internal static bool IsGenericMethodDefinition(IRuntimeMethodInfo method)
1415         {
1416             bool fRet = RuntimeMethodHandle.IsGenericMethodDefinition(method.Value);
1417             GC.KeepAlive(method);
1418             return fRet;
1419         }
1420
1421
1422         [System.Security.SecuritySafeCritical]  // auto-generated
1423         [ResourceExposure(ResourceScope.None)]
1424         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1425         internal extern static bool IsTypicalMethodDefinition(IRuntimeMethodInfo method);
1426
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);
1432  
1433         [System.Security.SecuritySafeCritical]  // auto-generated
1434         internal static IRuntimeMethodInfo GetTypicalMethodDefinition(IRuntimeMethodInfo method)
1435         {
1436             if (!IsTypicalMethodDefinition(method))
1437                 GetTypicalMethodDefinition(method, JitHelpers.GetObjectHandleOnStack(ref method));
1438
1439             return method;
1440         }
1441
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);
1447  
1448         [System.Security.SecuritySafeCritical]  // auto-generated
1449         internal static IRuntimeMethodInfo StripMethodInstantiation(IRuntimeMethodInfo method)
1450         {
1451             IRuntimeMethodInfo strippedMethod = method;
1452
1453             StripMethodInstantiation(method, JitHelpers.GetObjectHandleOnStack(ref strippedMethod));
1454
1455             return strippedMethod;
1456         }
1457
1458         [System.Security.SecuritySafeCritical]  // auto-generated
1459         [ResourceExposure(ResourceScope.None)]
1460         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1461         internal extern static bool IsDynamicMethod(RuntimeMethodHandleInternal method);
1462
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);
1468
1469         [System.Security.SecuritySafeCritical]  // auto-generated
1470         [ResourceExposure(ResourceScope.None)]
1471         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1472         internal extern static Resolver GetResolver(RuntimeMethodHandleInternal method);
1473
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);
1479     
1480         [System.Security.SecuritySafeCritical]  // auto-generated
1481         internal static RuntimeType GetCallerType(ref StackCrawlMark stackMark)
1482         {
1483             RuntimeType type = null;
1484             GetCallerType(JitHelpers.GetStackCrawlMarkHandle(ref stackMark), JitHelpers.GetObjectHandleOnStack(ref type));
1485             return type;
1486         }
1487
1488         [ResourceExposure(ResourceScope.None)]
1489         [MethodImpl(MethodImplOptions.InternalCall)]
1490         [System.Security.SecuritySafeCritical]  // auto-generated
1491         internal extern static MethodBody GetMethodBody(IRuntimeMethodInfo method, RuntimeType declaringType);
1492
1493         [System.Security.SecurityCritical]  // auto-generated
1494         [ResourceExposure(ResourceScope.None)]
1495         [MethodImpl(MethodImplOptions.InternalCall)]
1496         internal extern static bool IsConstructor(RuntimeMethodHandleInternal method);
1497
1498         [System.Security.SecurityCritical]  // auto-generated
1499         [ResourceExposure(ResourceScope.None)]
1500         [MethodImpl(MethodImplOptions.InternalCall)]
1501         internal extern static LoaderAllocator GetLoaderAllocator(RuntimeMethodHandleInternal method);
1502     }
1503
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
1514     {
1515         internal static RuntimeFieldHandleInternal EmptyHandle
1516         {
1517             get
1518             {
1519                 return new RuntimeFieldHandleInternal();
1520             }
1521         }
1522
1523         internal bool IsNullHandle()
1524         {
1525             return m_handle.IsNull();
1526         }
1527
1528         internal IntPtr Value
1529         {
1530             [SecurityCritical]
1531             get
1532             {
1533                 return m_handle;
1534             }
1535         }
1536
1537         [SecurityCritical]
1538         internal RuntimeFieldHandleInternal(IntPtr value)
1539         {
1540             m_handle = value;
1541         }
1542
1543         internal IntPtr m_handle;
1544     }
1545
1546     internal interface IRuntimeFieldInfo
1547     {
1548         RuntimeFieldHandleInternal Value
1549         {
1550             get;
1551         }
1552     }
1553
1554     [StructLayout(LayoutKind.Sequential)]
1555     internal class RuntimeFieldInfoStub : IRuntimeFieldInfo
1556     {
1557         [SecuritySafeCritical]
1558         public RuntimeFieldInfoStub(IntPtr methodHandleValue, object keepalive)
1559         {
1560             m_keepalive = keepalive;
1561             m_fieldHandle = new RuntimeFieldHandleInternal(methodHandleValue);
1562         }
1563
1564         // These unused variables are used to ensure that this class has the same layout as RuntimeFieldInfo
1565 #pragma warning disable 169
1566         object m_keepalive;
1567         object m_c;
1568         object m_d;
1569         int m_b;
1570         object m_e;
1571 #if FEATURE_REMOTING
1572         object m_f;
1573 #endif
1574         RuntimeFieldHandleInternal m_fieldHandle;
1575 #pragma warning restore 169
1576
1577         RuntimeFieldHandleInternal IRuntimeFieldInfo.Value
1578         {
1579             get
1580             {
1581                 return m_fieldHandle;
1582             }
1583         }
1584     }
1585
1586     [Serializable]
1587 [System.Runtime.InteropServices.ComVisible(true)]
1588     public unsafe struct RuntimeFieldHandle : ISerializable
1589     {
1590         // Returns handle for interop with EE. The handle is guaranteed to be non-null.
1591         internal RuntimeFieldHandle GetNativeHandle()
1592         {
1593             // Create local copy to avoid ----s
1594             IRuntimeFieldInfo field = m_ptr;
1595             if (field == null)
1596                 throw new ArgumentNullException(null, Environment.GetResourceString("Arg_InvalidHandle"));
1597             return new RuntimeFieldHandle(field);
1598         }
1599
1600         private IRuntimeFieldInfo m_ptr;
1601
1602         internal RuntimeFieldHandle(IRuntimeFieldInfo fieldInfo)
1603         {
1604             m_ptr = fieldInfo;
1605         }
1606
1607         internal IRuntimeFieldInfo GetRuntimeFieldInfo()
1608         {
1609             return m_ptr;
1610         }
1611
1612         public IntPtr Value
1613         {
1614 #if FEATURE_LEGACYNETCF
1615             [SecuritySafeCritical]
1616 #else
1617             [SecurityCritical]
1618 #endif
1619             get
1620             {
1621                 return m_ptr != null ? m_ptr.Value.Value : IntPtr.Zero;
1622             }
1623         }
1624
1625         internal bool IsNullHandle() 
1626         {
1627             return m_ptr == null; 
1628         }
1629
1630         [SecuritySafeCritical]
1631         public override int GetHashCode()
1632         {
1633             return ValueType.GetHashCodeOfPtr(Value);
1634         }
1635         
1636         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1637         [SecuritySafeCritical]
1638         public override bool Equals(object obj)
1639         {
1640             if (!(obj is RuntimeFieldHandle))
1641                 return false;
1642
1643             RuntimeFieldHandle handle = (RuntimeFieldHandle)obj;
1644
1645             return handle.Value == Value;
1646         }
1647
1648         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1649         [SecuritySafeCritical]
1650         public unsafe bool Equals(RuntimeFieldHandle handle)
1651         {
1652             return handle.Value == Value;
1653         }
1654
1655         public static bool operator ==(RuntimeFieldHandle left, RuntimeFieldHandle right)
1656         {
1657             return left.Equals(right);
1658         }
1659
1660         public static bool operator !=(RuntimeFieldHandle left, RuntimeFieldHandle right)
1661         {
1662             return !left.Equals(right);
1663         }
1664
1665         [System.Security.SecurityCritical]  // auto-generated
1666         [ResourceExposure(ResourceScope.None)]
1667         [MethodImplAttribute(MethodImplOptions.InternalCall)]        
1668         internal static extern String GetName(RtFieldInfo field); 
1669
1670         [System.Security.SecurityCritical]  // auto-generated
1671         [ResourceExposure(ResourceScope.None)]
1672         [MethodImplAttribute(MethodImplOptions.InternalCall)]        
1673         private static extern unsafe void* _GetUtf8Name(RuntimeFieldHandleInternal field); 
1674
1675         [System.Security.SecuritySafeCritical]  // auto-generated
1676         internal static unsafe Utf8String GetUtf8Name(RuntimeFieldHandleInternal field) { return new Utf8String(_GetUtf8Name(field)); }
1677
1678         [System.Security.SecurityCritical]  // auto-generated
1679         [ResourceExposure(ResourceScope.None)]
1680         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1681         internal static extern bool MatchesNameHash(RuntimeFieldHandleInternal handle, uint hash);
1682
1683         [System.Security.SecurityCritical]  // auto-generated
1684         [ResourceExposure(ResourceScope.None)]
1685         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1686         internal static extern FieldAttributes GetAttributes(RuntimeFieldHandleInternal field); 
1687         
1688         [System.Security.SecurityCritical]  // auto-generated
1689         [ResourceExposure(ResourceScope.None)]
1690         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1691         internal static extern RuntimeType GetApproxDeclaringType(RuntimeFieldHandleInternal field);
1692
1693         [System.Security.SecurityCritical]  // auto-generated
1694         internal static RuntimeType GetApproxDeclaringType(IRuntimeFieldInfo field)
1695         {
1696             RuntimeType type = GetApproxDeclaringType(field.Value);
1697             GC.KeepAlive(field);
1698             return type;
1699         }
1700
1701         [System.Security.SecurityCritical]  // auto-generated
1702         [ResourceExposure(ResourceScope.None)]
1703         [MethodImplAttribute(MethodImplOptions.InternalCall)]        
1704         internal static extern int GetToken(RtFieldInfo field); 
1705
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);
1710
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);
1715         
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);
1720
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);
1725
1726         [System.Security.SecurityCritical]  // auto-generated
1727         [ResourceExposure(ResourceScope.None)]
1728         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1729         internal static extern RuntimeFieldHandleInternal GetStaticFieldForGenericType(RuntimeFieldHandleInternal field, RuntimeType declaringType);
1730
1731         [System.Security.SecurityCritical]  // auto-generated
1732         [ResourceExposure(ResourceScope.None)]
1733         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1734         internal static extern bool AcquiresContextFromThis(RuntimeFieldHandleInternal field);
1735
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);
1742
1743         [System.Security.SecuritySafeCritical]  // auto-generated
1744         internal bool IsSecurityCritical()
1745         {
1746             return IsSecurityCritical(GetNativeHandle());
1747         }
1748
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);
1755
1756         [System.Security.SecuritySafeCritical]  // auto-generated
1757         internal bool IsSecuritySafeCritical()
1758         {
1759             return IsSecuritySafeCritical(GetNativeHandle());
1760         }
1761
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);
1768
1769         [System.Security.SecuritySafeCritical]  // auto-generated
1770         internal bool IsSecurityTransparent()
1771         {
1772             return IsSecurityTransparent(GetNativeHandle());
1773         }
1774
1775         [SecurityCritical]
1776         [ResourceExposure(ResourceScope.None)]
1777         [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
1778         [SuppressUnmanagedCodeSecurity]
1779         internal static extern void CheckAttributeAccess(RuntimeFieldHandle fieldHandle, RuntimeModule decoratedTarget);
1780
1781         // ISerializable interface
1782         [System.Security.SecurityCritical]  // auto-generated
1783         private RuntimeFieldHandle(SerializationInfo info, StreamingContext context)
1784         {
1785             if(info==null)
1786                 throw new ArgumentNullException("info");
1787             Contract.EndContractBlock();
1788             
1789             FieldInfo f =(RuntimeFieldInfo) info.GetValue("FieldObj", typeof(RuntimeFieldInfo));
1790             
1791             if( f == null)
1792                 throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
1793
1794             m_ptr = f.FieldHandle.m_ptr;
1795
1796             if (m_ptr == null)
1797                 throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
1798         }
1799
1800         [System.Security.SecurityCritical]
1801         public void GetObjectData(SerializationInfo info, StreamingContext context) 
1802         {
1803             if (info == null) 
1804                 throw new ArgumentNullException("info");
1805             Contract.EndContractBlock();
1806
1807             if (m_ptr == null)
1808                 throw new SerializationException(Environment.GetResourceString("Serialization_InvalidFieldState"));
1809
1810             RuntimeFieldInfo fldInfo = (RuntimeFieldInfo)RuntimeType.GetFieldInfo(this.GetRuntimeFieldInfo()); 
1811             
1812             info.AddValue("FieldObj",fldInfo, typeof(RuntimeFieldInfo));
1813         }
1814     }
1815
1816 [System.Runtime.InteropServices.ComVisible(true)]
1817     public unsafe struct ModuleHandle
1818     {
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();
1822         #endregion
1823
1824         unsafe static private ModuleHandle GetEmptyMH()
1825         {
1826             return new ModuleHandle();
1827         }
1828
1829         #region Private Data Members
1830         private RuntimeModule m_ptr;
1831         #endregion
1832     
1833         #region Constructor
1834         internal ModuleHandle(RuntimeModule module) 
1835         {
1836             m_ptr = module;
1837         }
1838         #endregion
1839
1840         #region Internal FCalls
1841
1842         internal RuntimeModule GetRuntimeModule()
1843         {
1844             return m_ptr;
1845         }
1846
1847         internal bool IsNullHandle() 
1848         { 
1849             return m_ptr == null; 
1850         }
1851         
1852         public override int GetHashCode()
1853         {           
1854             return m_ptr != null ? m_ptr.GetHashCode() : 0;
1855         }
1856
1857         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1858         public override bool Equals(object obj)
1859         {
1860             if (!(obj is ModuleHandle))
1861                 return false;
1862
1863             ModuleHandle handle = (ModuleHandle)obj;
1864
1865             return handle.m_ptr == m_ptr;
1866         }
1867
1868         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1869         public unsafe bool Equals(ModuleHandle handle)
1870         {
1871             return handle.m_ptr == m_ptr;
1872         }
1873
1874         public static bool operator ==(ModuleHandle left, ModuleHandle right)
1875         {
1876             return left.Equals(right);
1877         }
1878
1879         public static bool operator !=(ModuleHandle left, ModuleHandle right)
1880         {
1881             return !left.Equals(right);
1882         }
1883
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);
1888
1889         [System.Security.SecurityCritical]  // auto-generated
1890         [ResourceExposure(ResourceScope.None)]
1891         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1892         internal static extern int GetToken(RuntimeModule module);
1893
1894         private static void ValidateModulePointer(RuntimeModule module)
1895         {
1896             // Make sure we have a valid Module to resolve against.
1897             if (module == null)
1898                 throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullModuleHandle"));
1899         }
1900
1901         // SQL-CLR LKG9 Compiler dependency
1902         public RuntimeTypeHandle GetRuntimeTypeHandleFromMetadataToken(int typeToken) { return ResolveTypeHandle(typeToken); }
1903         public RuntimeTypeHandle ResolveTypeHandle(int typeToken) 
1904         {
1905             return new RuntimeTypeHandle(ResolveTypeHandleInternal(GetRuntimeModule(), typeToken, null, null));
1906         }
1907         public RuntimeTypeHandle ResolveTypeHandle(int typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) 
1908         {
1909             return new RuntimeTypeHandle(ModuleHandle.ResolveTypeHandleInternal(GetRuntimeModule(), typeToken, typeInstantiationContext, methodInstantiationContext));
1910         }
1911
1912         [System.Security.SecuritySafeCritical]  // auto-generated
1913         internal static RuntimeType ResolveTypeHandleInternal(RuntimeModule module, int typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
1914         {
1915             ValidateModulePointer(module);
1916             if (!ModuleHandle.GetMetadataImport(module).IsValidToken(typeToken))
1917                 throw new ArgumentOutOfRangeException("metadataToken",
1918                     Environment.GetResourceString("Argument_InvalidToken", typeToken, new ModuleHandle(module)));
1919             
1920             int typeInstCount, methodInstCount;
1921             IntPtr[] typeInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out typeInstCount);
1922             IntPtr[] methodInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out methodInstCount);
1923
1924             fixed (IntPtr* typeInstArgs = typeInstantiationContextHandles, methodInstArgs = methodInstantiationContextHandles)
1925             {
1926                 RuntimeType type = null;
1927                 ResolveType(module, typeToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount, JitHelpers.GetObjectHandleOnStack(ref type));
1928                 GC.KeepAlive(typeInstantiationContext);
1929                 GC.KeepAlive(methodInstantiationContext);
1930                 return type;
1931             }
1932         }
1933
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,
1939                                                             int typeToken,
1940                                                             IntPtr* typeInstArgs, 
1941                                                             int typeInstCount,
1942                                                             IntPtr* methodInstArgs,
1943                                                             int methodInstCount,
1944                                                             ObjectHandleOnStack type);
1945
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)
1951         {
1952             return new RuntimeMethodHandle(ResolveMethodHandleInternal(GetRuntimeModule(), methodToken, typeInstantiationContext, methodInstantiationContext));
1953         }
1954
1955         [System.Security.SecuritySafeCritical]  // auto-generated
1956         internal static IRuntimeMethodInfo ResolveMethodHandleInternal(RuntimeModule module, int methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
1957         {
1958             int typeInstCount, methodInstCount;
1959
1960             IntPtr[] typeInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out typeInstCount);
1961             IntPtr[] methodInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out methodInstCount);
1962
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);
1967             return retVal;
1968         }
1969
1970         [System.Security.SecurityCritical]  // auto-generated
1971         internal static RuntimeMethodHandleInternal ResolveMethodHandleInternalCore(RuntimeModule module, int methodToken, IntPtr[] typeInstantiationContext, int typeInstCount, IntPtr[] methodInstantiationContext, int methodInstCount)
1972         {
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)));
1977
1978             fixed (IntPtr* typeInstArgs = typeInstantiationContext, methodInstArgs = methodInstantiationContext)
1979             {
1980                 return ResolveMethod(module.GetNativeHandle(), methodToken, typeInstArgs, typeInstCount, methodInstArgs, methodInstCount);
1981             }
1982         }
1983
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,
1989                                                         int methodToken,
1990                                                         IntPtr* typeInstArgs, 
1991                                                         int typeInstCount,
1992                                                         IntPtr* methodInstArgs,
1993                                                         int methodInstCount);
1994
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)); }
2000
2001         [System.Security.SecuritySafeCritical]  // auto-generated
2002         internal static IRuntimeFieldInfo ResolveFieldHandleInternal(RuntimeModule module, int fieldToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
2003         {
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)));
2008             
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);
2013
2014             fixed (IntPtr* typeInstArgs = typeInstantiationContextHandles, methodInstArgs = methodInstantiationContextHandles)
2015             {
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);
2020                 return field;
2021             }
2022         }
2023
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,
2029                                                       int fieldToken,
2030                                                       IntPtr* typeInstArgs, 
2031                                                       int typeInstCount,
2032                                                       IntPtr* methodInstArgs,
2033                                                       int methodInstCount,
2034                                                       ObjectHandleOnStack retField);
2035
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);
2041
2042         [System.Security.SecurityCritical]  // auto-generated
2043         internal static bool ContainsPropertyMatchingHash(RuntimeModule module, int propertyToken, uint hash)
2044         {
2045             return _ContainsPropertyMatchingHash(module.GetNativeHandle(), propertyToken, hash);
2046         }
2047
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);
2053
2054         [System.Security.SecuritySafeCritical]  // auto-generated
2055         internal static RuntimeAssembly GetAssembly(RuntimeModule module)
2056         {
2057             RuntimeAssembly retAssembly = null;
2058             GetAssembly(module.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref retAssembly));
2059             return retAssembly;
2060         }
2061
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);
2067
2068         [System.Security.SecuritySafeCritical]  // auto-generated
2069         internal static RuntimeType GetModuleType(RuntimeModule module)
2070         {
2071             RuntimeType type = null;
2072             GetModuleType(module.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref type));
2073             return type;
2074         }
2075  
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);
2081    
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)
2085         {
2086             int lKind, lMachine;
2087             GetPEKind(module.GetNativeHandle(), out lKind, out lMachine);
2088             peKind = (PortableExecutableKinds)lKind;
2089             machine = (ImageFileMachine)lMachine;
2090         }
2091    
2092         [System.Security.SecurityCritical]  // auto-generated
2093         [MethodImplAttribute(MethodImplOptions.InternalCall)]        
2094         [ResourceExposure(ResourceScope.None)]
2095         internal extern static int GetMDStreamVersion(RuntimeModule module);
2096
2097         public int MDStreamVersion
2098         {
2099             [System.Security.SecuritySafeCritical]  // auto-generated
2100             get { return GetMDStreamVersion(GetRuntimeModule().GetNativeHandle()); }
2101         }
2102         
2103         [System.Security.SecurityCritical]  // auto-generated
2104         [ResourceExposure(ResourceScope.None)]
2105         [MethodImplAttribute(MethodImplOptions.InternalCall)]
2106         private extern static IntPtr _GetMetadataImport(RuntimeModule module);
2107
2108         [System.Security.SecurityCritical]  // auto-generated
2109         internal static MetadataImport GetMetadataImport(RuntimeModule module)
2110         {
2111             return new MetadataImport(_GetMetadataImport(module.GetNativeHandle()), module);
2112         }
2113         #endregion
2114     }
2115
2116     internal unsafe class Signature
2117     {
2118         #region Definitions
2119         internal enum MdSigCallingConvention : byte
2120         {
2121             Generics            = 0x10,
2122             HasThis             = 0x20,
2123             ExplicitThis        = 0x40,
2124             CallConvMask        = 0x0F,
2125             Default             = 0x00,
2126             C                   = 0x01,
2127             StdCall             = 0x02,
2128             ThisCall            = 0x03,
2129             FastCall            = 0x04,
2130             Vararg              = 0x05,
2131             Field               = 0x06,
2132             LocalSig            = 0x07,
2133             Property            = 0x08,
2134             Unmgd               = 0x09,
2135             GenericInst         = 0x0A,
2136             Max                 = 0x0B,
2137         }
2138         #endregion
2139
2140         #region FCalls
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);
2147
2148         #endregion
2149
2150         #region Private Data Members
2151         //
2152         // Keep the layout in sync with SignatureNative in the VM
2153         //
2154         internal RuntimeType[] m_arguments;
2155         internal RuntimeType m_declaringType;
2156         internal RuntimeType m_returnTypeORfieldType;
2157         internal object m_keepalive;
2158         [SecurityCritical]
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;
2164         #endregion
2165
2166         #region Constructors
2167         [System.Security.SecuritySafeCritical]  // auto-generated
2168         public Signature (
2169             IRuntimeMethodInfo method,
2170             RuntimeType[] arguments,
2171             RuntimeType returnType,
2172             CallingConventions callingConvention)
2173         {
2174             m_pMethod = method.Value;
2175             m_arguments = arguments;
2176             m_returnTypeORfieldType = returnType;
2177             m_managedCallingConventionAndArgIteratorFlags = (byte)callingConvention;
2178
2179             GetSignature(null, 0, new RuntimeFieldHandleInternal(), method, null);
2180         }
2181
2182         [System.Security.SecuritySafeCritical]  // auto-generated
2183         public Signature(IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
2184         {
2185             GetSignature(null, 0, new RuntimeFieldHandleInternal(), methodHandle, declaringType);
2186         }
2187
2188         [System.Security.SecurityCritical]  // auto-generated
2189         public Signature(IRuntimeFieldInfo fieldHandle, RuntimeType declaringType)
2190         {
2191             GetSignature(null, 0, fieldHandle.Value, null, declaringType);
2192             GC.KeepAlive(fieldHandle);
2193         }
2194
2195         [System.Security.SecurityCritical]  // auto-generated
2196         public Signature(void* pCorSig, int cCorSig, RuntimeType declaringType)
2197         {
2198             GetSignature(pCorSig, cCorSig, new RuntimeFieldHandleInternal(), null, declaringType);
2199         }
2200         #endregion
2201
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; } }
2207
2208         [System.Security.SecuritySafeCritical]
2209         [ResourceExposure(ResourceScope.None)]
2210         [MethodImplAttribute(MethodImplOptions.InternalCall)]
2211         internal static extern bool CompareSig(Signature sig1, Signature sig2);
2212
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); 
2218 #endif
2219
2220         [System.Security.SecuritySafeCritical]
2221         [ResourceExposure(ResourceScope.None)]
2222         [MethodImplAttribute(MethodImplOptions.InternalCall)]
2223         internal extern Type[] GetCustomModifiers(int position, bool required);
2224         #endregion
2225     }
2226
2227
2228     internal abstract class Resolver
2229     {
2230         internal struct CORINFO_EH_CLAUSE 
2231         {
2232             internal int Flags;
2233             internal int TryOffset;
2234             internal int TryLength;
2235             internal int HandlerOffset;
2236             internal int HandlerLength;
2237             internal int ClassTokenOrFilterOffset; 
2238         }
2239
2240         // ILHeader info
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();
2247         // token resolution
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);
2252         // 
2253         internal abstract MethodInfo GetDynamicMethod();
2254 #if FEATURE_COMPRESSEDSTACK
2255         internal abstract CompressedStack GetSecurityContext();
2256 #endif
2257     }
2258
2259 }