Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RuntimeTypeHandle.cs
Go to the documentation of this file.
9
10namespace System;
11
14{
16 {
17 private bool _firstCall;
18
20
22
28
29 public bool MoveNext()
30 {
31 if (_firstCall)
32 {
33 _firstCall = false;
34 }
35 else if (_handle.Value != IntPtr.Zero)
36 {
38 }
39 return !(_handle.Value == IntPtr.Zero);
40 }
41
43 {
44 return this;
45 }
46 }
47
49
51 {
52 get
53 {
54 if (!(m_type != null))
55 {
56 return IntPtr.Zero;
57 }
58 return m_type.m_handle;
59 }
60 }
61
63 {
65 if (type == null)
66 {
68 }
69 return new RuntimeTypeHandle(type);
70 }
71
73 {
75 if (type == null)
76 {
78 }
79 return type;
80 }
81
82 [MethodImpl(MethodImplOptions.InternalCall)]
83 internal static extern bool IsInstanceOfType(RuntimeType type, [NotNullWhen(true)] object o);
84
85 [RequiresUnreferencedCode("MakeGenericType cannot be statically analyzed. It's not possible to guarantee the availability of requirements of the generic type.")]
87 {
89 if (genericArgs != null)
90 {
92 }
93 if (cModifiers > 0)
94 {
95 int* ptr = (int*)pModifiers.ToPointer();
96 for (int i = 0; i < cModifiers; i++)
97 {
98 type = (((byte)Marshal.ReadInt32((IntPtr)ptr, i * 4) != 15) ? (((byte)Marshal.ReadInt32((IntPtr)ptr, i * 4) != 16) ? (((byte)Marshal.ReadInt32((IntPtr)ptr, i * 4) != 29) ? type.MakeArrayType(Marshal.ReadInt32((IntPtr)ptr, ++i * 4)) : type.MakeArrayType()) : type.MakeByRefType()) : type.MakePointerType());
99 }
100 }
101 return type;
102 }
103
104 public static bool operator ==(RuntimeTypeHandle left, object? right)
105 {
106 return left.Equals(right);
107 }
108
109 public static bool operator ==(object? left, RuntimeTypeHandle right)
110 {
111 return right.Equals(left);
112 }
113
114 public static bool operator !=(RuntimeTypeHandle left, object? right)
115 {
116 return !left.Equals(right);
117 }
118
119 public static bool operator !=(object? left, RuntimeTypeHandle right)
120 {
121 return !right.Equals(left);
122 }
123
124 public override int GetHashCode()
125 {
126 if (!(m_type != null))
127 {
128 return 0;
129 }
130 return m_type.GetHashCode();
131 }
132
133 public override bool Equals(object? obj)
134 {
136 {
137 return false;
138 }
140 }
141
143 {
144 return handle.m_type == m_type;
145 }
146
147 [MethodImpl(MethodImplOptions.InternalCall)]
148 [Intrinsic]
150
152 {
153 m_type = type;
154 }
155
156 internal static bool IsTypeDefinition(RuntimeType type)
157 {
159 if (((int)corElementType < 1 || (int)corElementType >= 15) && corElementType != CorElementType.ELEMENT_TYPE_VALUETYPE && corElementType != CorElementType.ELEMENT_TYPE_CLASS && corElementType != CorElementType.ELEMENT_TYPE_TYPEDBYREF && corElementType != CorElementType.ELEMENT_TYPE_I && corElementType != CorElementType.ELEMENT_TYPE_U && corElementType != CorElementType.ELEMENT_TYPE_OBJECT)
160 {
161 return false;
162 }
164 {
165 return false;
166 }
167 return true;
168 }
169
170 internal static bool IsPrimitive(RuntimeType type)
171 {
172 return GetCorElementType(type).IsPrimitiveType();
173 }
174
175 internal static bool IsByRef(RuntimeType type)
176 {
178 return corElementType == CorElementType.ELEMENT_TYPE_BYREF;
179 }
180
181 internal static bool IsPointer(RuntimeType type)
182 {
184 return corElementType == CorElementType.ELEMENT_TYPE_PTR;
185 }
186
187 internal static bool IsArray(RuntimeType type)
188 {
190 if (corElementType != CorElementType.ELEMENT_TYPE_ARRAY)
191 {
192 return corElementType == CorElementType.ELEMENT_TYPE_SZARRAY;
193 }
194 return true;
195 }
196
197 internal static bool IsSZArray(RuntimeType type)
198 {
200 return corElementType == CorElementType.ELEMENT_TYPE_SZARRAY;
201 }
202
203 internal static bool HasElementType(RuntimeType type)
204 {
206 if (corElementType != CorElementType.ELEMENT_TYPE_ARRAY && corElementType != CorElementType.ELEMENT_TYPE_SZARRAY && corElementType != CorElementType.ELEMENT_TYPE_PTR)
207 {
208 return corElementType == CorElementType.ELEMENT_TYPE_BYREF;
209 }
210 return true;
211 }
212
214 {
215 if (inHandles == null || inHandles.Length == 0)
216 {
217 length = 0;
218 return null;
219 }
220 IntPtr[] array = new IntPtr[inHandles.Length];
221 for (int i = 0; i < inHandles.Length; i++)
222 {
223 array[i] = inHandles[i].Value;
224 }
225 length = array.Length;
226 return array;
227 }
228
230 {
231 if (inHandles == null || inHandles.Length == 0)
232 {
233 length = 0;
234 return null;
235 }
236 IntPtr[] array = new IntPtr[inHandles.Length];
237 for (int i = 0; i < inHandles.Length; i++)
238 {
239 array[i] = inHandles[i].GetTypeHandleInternal().Value;
240 }
241 length = array.Length;
242 return array;
243 }
244
246 {
247 object o = null;
248 IntPtr value = genericParameter.GetTypeHandleInternal().Value;
251 return o;
252 }
253
255 {
256 object o = null;
258 {
259 genericParameter1.GetTypeHandleInternal().Value,
260 genericParameter2.GetTypeHandleInternal().Value
261 };
265 return o;
266 }
267
268 [DllImport("QCall", CharSet = CharSet.Unicode)]
270
271 internal unsafe static void GetActivationInfo(RuntimeType rt, out delegate*<void*, object> pfnAllocator, out void* vAllocatorFirstArg, out delegate*<object, void> pfnCtor, out bool ctorIsPublic)
272 {
273 delegate*<void*, object> delegate_002A = default(delegate*<void*, object>);
274 void* ptr = default(void*);
275 delegate*<object, void> delegate_002A2 = default(delegate*<object, void>);
281 ctorIsPublic = bOOL != Interop.BOOL.FALSE;
282 }
283
284 [DllImport("QCall", CharSet = CharSet.Unicode)]
285 private unsafe static extern void GetActivationInfo(ObjectHandleOnStack pRuntimeType, delegate*<void*, object>* ppfnAllocator, void** pvAllocatorFirstArg, delegate*<object, void>* ppfnCtor, Interop.BOOL* pfCtorIsPublic);
286
287 [MethodImpl(MethodImplOptions.InternalCall)]
288 private unsafe static extern object AllocateComObject(void* pClassFactory);
289
291 {
292 return m_type;
293 }
294
295 [MethodImpl(MethodImplOptions.InternalCall)]
297
298 [MethodImpl(MethodImplOptions.InternalCall)]
300
301 [MethodImpl(MethodImplOptions.InternalCall)]
302 internal static extern RuntimeModule GetModule(RuntimeType type);
303
305 {
306 return new ModuleHandle(GetModule(m_type));
307 }
308
309 [MethodImpl(MethodImplOptions.InternalCall)]
310 internal static extern RuntimeType GetBaseType(RuntimeType type);
311
312 [MethodImpl(MethodImplOptions.InternalCall)]
314
315 [MethodImpl(MethodImplOptions.InternalCall)]
317
318 [MethodImpl(MethodImplOptions.InternalCall)]
319 internal static extern bool CompareCanonicalHandles(RuntimeType left, RuntimeType right);
320
321 [MethodImpl(MethodImplOptions.InternalCall)]
322 internal static extern int GetArrayRank(RuntimeType type);
323
324 [MethodImpl(MethodImplOptions.InternalCall)]
325 internal static extern int GetToken(RuntimeType type);
326
327 [MethodImpl(MethodImplOptions.InternalCall)]
329
334
335 [MethodImpl(MethodImplOptions.InternalCall)]
337
338 [MethodImpl(MethodImplOptions.InternalCall)]
340
341 [MethodImpl(MethodImplOptions.InternalCall)]
342 internal unsafe static extern bool GetFields(RuntimeType type, IntPtr* result, int* count);
343
344 [MethodImpl(MethodImplOptions.InternalCall)]
345 internal static extern Type[] GetInterfaces(RuntimeType type);
346
347 [DllImport("QCall", CharSet = CharSet.Unicode)]
349
350 internal Type[] GetConstraints()
351 {
352 Type[] o = null;
355 return o;
356 }
357
358 [DllImport("QCall", CharSet = CharSet.Unicode)]
360
366
367 [DllImport("QCall", CharSet = CharSet.Unicode)]
369
375
376 [MethodImpl(MethodImplOptions.InternalCall)]
377 internal static extern int GetNumVirtuals(RuntimeType type);
378
379 [MethodImpl(MethodImplOptions.InternalCall)]
381
382 [DllImport("QCall", CharSet = CharSet.Unicode)]
384
391
392 [DllImport("QCall", CharSet = CharSet.Unicode)]
394
401
402 internal static bool IsComObject(RuntimeType type, bool isGenericCOM)
403 {
404 if (isGenericCOM)
405 {
406 return type.TypeHandle.Value == typeof(__ComObject).TypeHandle.Value;
407 }
409 }
410
411 [MethodImpl(MethodImplOptions.InternalCall)]
412 internal static extern bool IsInterface(RuntimeType type);
413
414 [MethodImpl(MethodImplOptions.InternalCall)]
415 internal static extern bool IsByRefLike(RuntimeType type);
416
417 [DllImport("QCall", CharSet = CharSet.Unicode)]
418 [return: MarshalAs(UnmanagedType.Bool)]
419 private static extern bool _IsVisible(QCallTypeHandle typeHandle);
420
421 internal static bool IsVisible(RuntimeType type)
422 {
423 return _IsVisible(new QCallTypeHandle(ref type));
424 }
425
426 [MethodImpl(MethodImplOptions.InternalCall)]
427 internal static extern bool IsValueType(RuntimeType type);
428
429 [DllImport("QCall", CharSet = CharSet.Unicode)]
431
432 internal string ConstructName(TypeNameFormatFlags formatFlags)
433 {
434 string s = null;
437 return s;
438 }
439
440 [MethodImpl(MethodImplOptions.InternalCall)]
441 private unsafe static extern void* _GetUtf8Name(RuntimeType type);
442
443 internal unsafe static MdUtf8String GetUtf8Name(RuntimeType type)
444 {
445 return new MdUtf8String(_GetUtf8Name(type));
446 }
447
448 [MethodImpl(MethodImplOptions.InternalCall)]
449 internal static extern bool CanCastTo(RuntimeType type, RuntimeType target);
450
451 [MethodImpl(MethodImplOptions.InternalCall)]
453
454 [MethodImpl(MethodImplOptions.InternalCall)]
456
457 [DllImport("QCall", CharSet = CharSet.Unicode)]
459
464
466 {
467 if (string.IsNullOrEmpty(name))
468 {
469 if (throwOnError)
470 {
472 }
473 return null;
474 }
475 RuntimeType o = null;
476 object o2 = null;
479 GC.KeepAlive(o2);
480 return o;
481 }
482
483 [DllImport("QCall", CharSet = CharSet.Unicode)]
484 private static extern void GetTypeByNameUsingCARules(string name, QCallModule scope, ObjectHandleOnStack type);
485
486 internal static RuntimeType GetTypeByNameUsingCARules(string name, RuntimeModule scope)
487 {
488 if (string.IsNullOrEmpty(name))
489 {
490 throw new ArgumentException(null, "name");
491 }
492 RuntimeType o = null;
494 return o;
495 }
496
497 [DllImport("QCall", CharSet = CharSet.Unicode)]
499
507
509 {
510 Type[] o = null;
513 return o;
514 }
515
516 [DllImport("QCall", CharSet = CharSet.Unicode)]
518
520 {
521 IntPtr value = inst.TypeHandle.Value;
522 RuntimeType o = null;
526 return o;
527 }
528
529 internal unsafe RuntimeType Instantiate(Type[] inst)
530 {
531 int length;
533 {
534 RuntimeType o = null;
538 return o;
539 }
540 }
541
542 [DllImport("QCall", CharSet = CharSet.Unicode)]
543 private static extern void MakeArray(QCallTypeHandle handle, int rank, ObjectHandleOnStack type);
544
546 {
547 RuntimeType o = null;
550 return o;
551 }
552
553 [DllImport("QCall", CharSet = CharSet.Unicode)]
555
557 {
558 RuntimeType o = null;
561 return o;
562 }
563
564 [DllImport("QCall", CharSet = CharSet.Unicode)]
566
568 {
569 RuntimeType o = null;
572 return o;
573 }
574
575 [DllImport("QCall", CharSet = CharSet.Unicode)]
577
579 {
580 RuntimeType o = null;
583 return o;
584 }
585
586 [DllImport("QCall", CharSet = CharSet.Unicode)]
588
589 [MethodImpl(MethodImplOptions.InternalCall)]
590 internal static extern bool HasInstantiation(RuntimeType type);
591
592 [DllImport("QCall", CharSet = CharSet.Unicode)]
594
596 {
599 {
600 RuntimeTypeHandle rth = o.GetTypeHandleInternal();
602 }
603 return o;
604 }
605
606 [MethodImpl(MethodImplOptions.InternalCall)]
607 internal static extern bool IsGenericTypeDefinition(RuntimeType type);
608
609 [MethodImpl(MethodImplOptions.InternalCall)]
610 internal static extern bool IsGenericVariable(RuntimeType type);
611
612 [MethodImpl(MethodImplOptions.InternalCall)]
613 private static extern int GetGenericVariableIndex(RuntimeType type);
614
624
625 [MethodImpl(MethodImplOptions.InternalCall)]
626 internal static extern bool ContainsGenericVariables(RuntimeType handle);
627
629 {
631 }
632
633 [MethodImpl(MethodImplOptions.InternalCall)]
635
655
656 [MethodImpl(MethodImplOptions.InternalCall)]
658
663
665 {
667 }
668
669 [MethodImpl(MethodImplOptions.InternalCall)]
670 internal static extern bool IsEquivalentTo(RuntimeType rtType1, RuntimeType rtType2);
671}
static void KeepAlive(object? obj)
Definition GC.cs:180
Definition GC.cs:8
override int GetHashCode()
static int ReadInt32(object ptr, int ofs)
Definition Marshal.cs:59
static ? AssemblyLoadContext CurrentContextualReflectionContext
static string Arg_TypeLoadNullStr
Definition SR.cs:434
static string Arg_InvalidHandle
Definition SR.cs:14
static string Arg_NotGenericParameter
Definition SR.cs:346
Definition SR.cs:7
virtual Type MakeGenericType(params Type[] typeArguments)
Definition Type.cs:1074
static readonly IntPtr Zero
Definition IntPtr.cs:18
static bool IsPrimitive(RuntimeType type)
static IntPtr[] CopyRuntimeTypeHandles(Type[] inHandles, out int length)
static void VerifyInterfaceIsImplemented(QCallTypeHandle handle, QCallTypeHandle interfaceHandle)
static void GetConstraints(QCallTypeHandle handle, ObjectHandleOnStack types)
static IntPtr GetGCHandle(QCallTypeHandle handle, GCHandleType type)
static unsafe Type GetTypeHelper(Type typeStart, Type[] genericArgs, IntPtr pModifiers, int cModifiers)
static void MakePointer(QCallTypeHandle handle, ObjectHandleOnStack type)
static bool IsValueType(RuntimeType type)
static IntPtr[] CopyRuntimeTypeHandles(RuntimeTypeHandle[] inHandles, out int length)
static RuntimeType GetDeclaringType(RuntimeType type)
static bool IsComObject(RuntimeType type, bool isGenericCOM)
static bool IsPointer(RuntimeType type)
static TypeAttributes GetAttributes(RuntimeType type)
static unsafe bool GetFields(RuntimeType type, IntPtr *result, int *count)
static void GetTypeByName(string name, bool throwOnError, bool ignoreCase, StackCrawlMarkHandle stackMark, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
static IntroducedMethodEnumerator GetIntroducedMethods(RuntimeType type)
void GetObjectData(SerializationInfo info, StreamingContext context)
static bool IsByRefLike(RuntimeType type)
static IntPtr FreeGCHandle(QCallTypeHandle typeHandle, IntPtr objHandle)
static void MakeSZArray(QCallTypeHandle handle, ObjectHandleOnStack type)
static void GetGenericTypeDefinition(QCallTypeHandle type, ObjectHandleOnStack retType)
static MetadataImport GetMetadataImport(RuntimeType type)
static bool IsInterface(RuntimeType type)
static bool CanCastTo(RuntimeType type, RuntimeType target)
static bool operator!=(RuntimeTypeHandle left, object? right)
static RuntimeMethodHandleInternal GetFirstIntroducedMethod(RuntimeType type)
static RuntimeModule GetModule(RuntimeType type)
static bool ContainsGenericVariables(RuntimeType handle)
string ConstructName(TypeNameFormatFlags formatFlags)
static void MakeByRef(QCallTypeHandle handle, ObjectHandleOnStack type)
static unsafe bool SatisfiesConstraints(RuntimeType paramType, RuntimeType[] typeContext, RuntimeType[] methodContext, RuntimeType toType)
static Type[] GetInterfaces(RuntimeType type)
static unsafe MdUtf8String GetUtf8Name(RuntimeType type)
unsafe RuntimeType Instantiate(RuntimeType inst)
RuntimeTypeHandle(RuntimeType type)
static int GetToken(RuntimeType type)
static unsafe object CreateInstanceForAnotherGenericParameter([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] RuntimeType type, RuntimeType genericParameter)
static bool HasInstantiation(RuntimeType type)
static bool IsByRef(RuntimeType type)
IntPtr GetGCHandle(GCHandleType type)
override bool Equals(object? obj)
static RuntimeMethodHandleInternal GetInterfaceMethodImplementation(QCallTypeHandle handle, QCallTypeHandle interfaceHandle, RuntimeMethodHandleInternal interfaceMethodHandle)
static bool IsVisible(RuntimeType type)
static bool IsGenericTypeDefinition(RuntimeType type)
static bool IsSZArray(RuntimeType type)
static int GetNumVirtualsAndStaticVirtuals(RuntimeType type)
static RuntimeType GetTypeByName(string name, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark)
static RuntimeType GetGenericTypeDefinition(RuntimeType type)
static RuntimeAssembly GetAssembly(RuntimeType type)
RuntimeType[] GetInstantiationInternal()
static RuntimeType GetElementType(RuntimeType type)
static RuntimeType GetTypeByName(string name, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark, AssemblyLoadContext assemblyLoadContext)
static unsafe void GetActivationInfo(RuntimeType rt, out delegate *< void *, object > pfnAllocator, out void *vAllocatorFirstArg, out delegate *< object, void > pfnCtor, out bool ctorIsPublic)
static void GetNextIntroducedMethod(ref RuntimeMethodHandleInternal method)
static void MakeArray(QCallTypeHandle handle, int rank, ObjectHandleOnStack type)
static Interop.BOOL IsCollectible(QCallTypeHandle handle)
static bool IsGenericVariable(RuntimeType type)
static RuntimeMethodHandleInternal GetMethodAt(RuntimeType type, int slot)
static IntPtr GetValueInternal(RuntimeTypeHandle handle)
static void GetInstantiation(QCallTypeHandle type, ObjectHandleOnStack types, Interop.BOOL fAsRuntimeTypeArray)
RuntimeType MakeArray(int rank)
static void ConstructName(QCallTypeHandle handle, TypeNameFormatFlags formatFlags, StringHandleOnStack retString)
unsafe RuntimeType Instantiate(Type[] inst)
IntPtr FreeGCHandle(IntPtr objHandle)
static bool IsEquivalentTo(RuntimeType rtType1, RuntimeType rtType2)
static unsafe void Instantiate(QCallTypeHandle handle, IntPtr *pInst, int numGenericArgs, ObjectHandleOnStack type)
static bool HasElementType(RuntimeType type)
static unsafe object AllocateComObject(void *pClassFactory)
static int GetGenericVariableIndex(RuntimeType type)
static bool IsArray(RuntimeType type)
static unsafe bool SatisfiesConstraints(RuntimeType paramType, IntPtr *pTypeContext, int typeContextLength, IntPtr *pMethodContext, int methodContextLength, RuntimeType toType)
RuntimeTypeHandle GetNativeHandle()
static CorElementType GetCorElementType(RuntimeType type)
static unsafe object CreateInstanceForAnotherGenericParameter([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] RuntimeType type, RuntimeType genericParameter1, RuntimeType genericParameter2)
static bool operator==(RuntimeTypeHandle left, object? right)
static unsafe void CreateInstanceForAnotherGenericParameter(QCallTypeHandle baseType, IntPtr *pTypeHandles, int cTypeHandles, ObjectHandleOnStack instantiatedObject)
static bool CompareCanonicalHandles(RuntimeType left, RuntimeType right)
RuntimeMethodHandleInternal GetInterfaceMethodImplementation(RuntimeTypeHandle interfaceHandle, RuntimeMethodHandleInternal interfaceMethodHandle)
static void GetTypeByNameUsingCARules(string name, QCallModule scope, ObjectHandleOnStack type)
static bool _IsVisible(QCallTypeHandle typeHandle)
static unsafe void * _GetUtf8Name(RuntimeType type)
static unsafe void GetActivationInfo(ObjectHandleOnStack pRuntimeType, delegate *< void *, object > *ppfnAllocator, void **pvAllocatorFirstArg, delegate *< object, void > *ppfnCtor, Interop.BOOL *pfCtorIsPublic)
static IntPtr _GetMetadataImport(RuntimeType type)
static IRuntimeMethodInfo GetDeclaringMethod(RuntimeType type)
bool Equals(RuntimeTypeHandle handle)
void VerifyInterfaceIsImplemented(RuntimeTypeHandle interfaceHandle)
static RuntimeType GetBaseType(RuntimeType type)
static bool IsInstanceOfType(RuntimeType type, [NotNullWhen(true)] object o)
static int GetNumVirtuals(RuntimeType type)
static int GetArrayRank(RuntimeType type)
static RuntimeType GetTypeByNameUsingCARules(string name, RuntimeModule scope)
static bool IsTypeDefinition(RuntimeType type)