Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TypeUtils.cs
Go to the documentation of this file.
2using System.Linq;
5
7
8internal static class TypeUtils
9{
10 private static readonly Type[] s_arrayAssignableInterfaces = (from i in typeof(int[]).GetInterfaces()
11 where i.IsGenericType
12 select i.GetGenericTypeDefinition()).ToArray();
13
14 private static readonly ConstructorInfo s_nullableConstructor = typeof(Nullable<>).GetConstructor(typeof(Nullable<>).GetGenericArguments());
15
16 public static Type GetNonNullableType(this Type type)
17 {
18 if (!type.IsNullableType())
19 {
20 return type;
21 }
22 return type.GetGenericArguments()[0];
23 }
24
25 public static Type GetNullableType(this Type type)
26 {
27 if (type.IsValueType && !type.IsNullableType())
28 {
29 return typeof(Nullable<>).MakeGenericType(type);
30 }
31 return type;
32 }
33
38
39 public static bool IsNullableType(this Type type)
40 {
41 if (type.IsConstructedGenericType)
42 {
43 return type.GetGenericTypeDefinition() == typeof(Nullable<>);
44 }
45 return false;
46 }
47
48 public static bool IsNullableOrReferenceType(this Type type)
49 {
50 if (type.IsValueType)
51 {
52 return type.IsNullableType();
53 }
54 return true;
55 }
56
57 public static bool IsBool(this Type type)
58 {
59 return type.GetNonNullableType() == typeof(bool);
60 }
61
62 public static bool IsNumeric(this Type type)
63 {
64 type = type.GetNonNullableType();
65 if (!type.IsEnum)
66 {
67 TypeCode typeCode = type.GetTypeCode();
68 if ((uint)(typeCode - 4) <= 10u)
69 {
70 return true;
71 }
72 }
73 return false;
74 }
75
76 public static bool IsInteger(this Type type)
77 {
78 type = type.GetNonNullableType();
79 if (!type.IsEnum)
80 {
81 TypeCode typeCode = type.GetTypeCode();
82 if ((uint)(typeCode - 5) <= 7u)
83 {
84 return true;
85 }
86 }
87 return false;
88 }
89
90 public static bool IsInteger64(this Type type)
91 {
92 type = type.GetNonNullableType();
93 if (!type.IsEnum)
94 {
95 TypeCode typeCode = type.GetTypeCode();
96 if ((uint)(typeCode - 11) <= 1u)
97 {
98 return true;
99 }
100 }
101 return false;
102 }
103
104 public static bool IsArithmetic(this Type type)
105 {
106 type = type.GetNonNullableType();
107 if (!type.IsEnum)
108 {
109 TypeCode typeCode = type.GetTypeCode();
110 if ((uint)(typeCode - 7) <= 7u)
111 {
112 return true;
113 }
114 }
115 return false;
116 }
117
118 public static bool IsUnsignedInt(this Type type)
119 {
120 type = type.GetNonNullableType();
121 if (!type.IsEnum)
122 {
123 switch (type.GetTypeCode())
124 {
125 case TypeCode.UInt16:
126 case TypeCode.UInt32:
127 case TypeCode.UInt64:
128 return true;
129 }
130 }
131 return false;
132 }
133
134 public static bool IsIntegerOrBool(this Type type)
135 {
136 type = type.GetNonNullableType();
137 if (!type.IsEnum)
138 {
139 TypeCode typeCode = type.GetTypeCode();
140 if (typeCode == TypeCode.Boolean || (uint)(typeCode - 5) <= 7u)
141 {
142 return true;
143 }
144 }
145 return false;
146 }
147
148 public static bool IsNumericOrBool(this Type type)
149 {
150 if (!type.IsNumeric())
151 {
152 return type.IsBool();
153 }
154 return true;
155 }
156
157 public static bool IsValidInstanceType(MemberInfo member, Type instanceType)
158 {
159 Type declaringType = member.DeclaringType;
160 if (declaringType == null)
161 {
162 return false;
163 }
164 if (AreReferenceAssignable(declaringType, instanceType))
165 {
166 return true;
167 }
168 if (instanceType.IsValueType)
169 {
170 if (AreReferenceAssignable(declaringType, typeof(object)))
171 {
172 return true;
173 }
174 if (AreReferenceAssignable(declaringType, typeof(ValueType)))
175 {
176 return true;
177 }
178 if (instanceType.IsEnum && AreReferenceAssignable(declaringType, typeof(Enum)))
179 {
180 return true;
181 }
182 if (declaringType.IsInterface)
183 {
184 Type[] array = GetTypeInterfaces(instanceType);
185 foreach (Type src in array)
186 {
187 if (AreReferenceAssignable(declaringType, src))
188 {
189 return true;
190 }
191 }
192 }
193 }
194 return false;
195 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", Justification = "The targetType must be preserved (since we have an instance of it here),So if it's an interface that interface will be preserved everywhereSo if it was implemented by the instanceType, it will be kept even after trimming.The fact that GetInterfaces may return fewer interfaces doesn't matter as longas it returns the one we're looking for.")]
196 static Type[] GetTypeInterfaces(Type instanceType)
197 {
198 return instanceType.GetInterfaces();
199 }
200 }
201
203 {
204 if (AreEquivalent(source, dest))
205 {
206 return true;
207 }
208 if (source.IsNullableType() && AreEquivalent(dest, source.GetNonNullableType()))
209 {
210 return true;
211 }
212 if (dest.IsNullableType() && AreEquivalent(source, dest.GetNonNullableType()))
213 {
214 return true;
215 }
216 if (source.IsConvertible() && dest.IsConvertible())
217 {
218 if (!(dest.GetNonNullableType() != typeof(bool)))
219 {
220 if (source.IsEnum)
221 {
222 return source.GetEnumUnderlyingType() == typeof(bool);
223 }
224 return false;
225 }
226 return true;
227 }
228 return false;
229 }
230
231 public static bool HasReferenceConversionTo(this Type source, Type dest)
232 {
233 if (source == typeof(void) || dest == typeof(void))
234 {
235 return false;
236 }
237 Type nonNullableType = source.GetNonNullableType();
238 Type nonNullableType2 = dest.GetNonNullableType();
239 if (nonNullableType.IsAssignableFrom(nonNullableType2))
240 {
241 return true;
242 }
243 if (nonNullableType2.IsAssignableFrom(nonNullableType))
244 {
245 return true;
246 }
247 if (source.IsInterface || dest.IsInterface)
248 {
249 return true;
250 }
252 {
253 return true;
254 }
255 if (source.IsArray || dest.IsArray)
256 {
257 return source.StrictHasReferenceConversionTo(dest, skipNonArray: true);
258 }
259 return false;
260 }
261
262 private static bool StrictHasReferenceConversionTo(this Type source, Type dest, bool skipNonArray)
263 {
264 while (true)
265 {
266 if (!skipNonArray)
267 {
268 if (source.IsValueType | dest.IsValueType)
269 {
270 return false;
271 }
272 if (source.IsAssignableFrom(dest) || dest.IsAssignableFrom(source))
273 {
274 return true;
275 }
276 if (source.IsInterface)
277 {
278 if (dest.IsInterface || (dest.IsClass && !dest.IsSealed))
279 {
280 return true;
281 }
282 }
283 else if (dest.IsInterface && source.IsClass && !source.IsSealed)
284 {
285 return true;
286 }
287 }
288 if (!source.IsArray)
289 {
290 break;
291 }
292 if (dest.IsArray)
293 {
294 if (source.GetArrayRank() != dest.GetArrayRank() || source.IsSZArray != dest.IsSZArray)
295 {
296 return false;
297 }
298 source = source.GetElementType();
299 dest = dest.GetElementType();
300 skipNonArray = false;
301 continue;
302 }
304 }
305 if (dest.IsArray)
306 {
308 {
309 return true;
310 }
312 }
314 }
315
317 {
318 if (!source.IsSZArray || !dest.IsInterface || !dest.IsGenericType)
319 {
320 return false;
321 }
322 Type[] genericArguments = dest.GetGenericArguments();
323 if (genericArguments.Length != 1)
324 {
325 return false;
326 }
327 Type genericTypeDefinition = dest.GetGenericTypeDefinition();
329 foreach (Type t in array)
330 {
331 if (AreEquivalent(genericTypeDefinition, t))
332 {
333 return source.GetElementType().StrictHasReferenceConversionTo(genericArguments[0], skipNonArray: false);
334 }
335 }
336 return false;
337 }
338
340 {
341 if (!dest.IsSZArray || !source.IsInterface || !source.IsGenericType)
342 {
343 return false;
344 }
345 Type[] genericArguments = source.GetGenericArguments();
346 if (genericArguments.Length != 1)
347 {
348 return false;
349 }
350 Type genericTypeDefinition = source.GetGenericTypeDefinition();
352 foreach (Type t in array)
353 {
354 if (AreEquivalent(genericTypeDefinition, t))
355 {
356 return genericArguments[0].StrictHasReferenceConversionTo(dest.GetElementType(), skipNonArray: false);
357 }
358 }
359 return false;
360 }
361
362 private static bool IsCovariant(Type t)
363 {
364 return (t.GenericParameterAttributes & GenericParameterAttributes.Covariant) != 0;
365 }
366
367 private static bool IsContravariant(Type t)
368 {
369 return (t.GenericParameterAttributes & GenericParameterAttributes.Contravariant) != 0;
370 }
371
372 private static bool IsInvariant(Type t)
373 {
374 return (t.GenericParameterAttributes & GenericParameterAttributes.VarianceMask) == 0;
375 }
376
377 private static bool IsDelegate(Type t)
378 {
379 return t.IsSubclassOf(typeof(MulticastDelegate));
380 }
381
383 {
384 if (!IsDelegate(source) || !IsDelegate(dest) || !source.IsGenericType || !dest.IsGenericType)
385 {
386 return false;
387 }
388 Type genericTypeDefinition = source.GetGenericTypeDefinition();
389 if (dest.GetGenericTypeDefinition() != genericTypeDefinition)
390 {
391 return false;
392 }
393 Type[] genericArguments = genericTypeDefinition.GetGenericArguments();
394 Type[] genericArguments2 = source.GetGenericArguments();
395 Type[] genericArguments3 = dest.GetGenericArguments();
396 for (int i = 0; i < genericArguments.Length; i++)
397 {
398 Type type = genericArguments2[i];
399 Type type2 = genericArguments3[i];
400 if (AreEquivalent(type, type2))
401 {
402 continue;
403 }
404 Type t = genericArguments[i];
405 if (IsInvariant(t))
406 {
407 return false;
408 }
409 if (IsCovariant(t))
410 {
411 if (!type.HasReferenceConversionTo(type2))
412 {
413 return false;
414 }
415 }
416 else if (IsContravariant(t) && (type.IsValueType || type2.IsValueType))
417 {
418 return false;
419 }
420 }
421 return true;
422 }
423
424 public static bool IsConvertible(this Type type)
425 {
426 type = type.GetNonNullableType();
427 if (type.IsEnum)
428 {
429 return true;
430 }
431 TypeCode typeCode = type.GetTypeCode();
432 if ((uint)(typeCode - 3) <= 11u)
433 {
434 return true;
435 }
436 return false;
437 }
438
439 public static bool HasReferenceEquality(Type left, Type right)
440 {
441 if (left.IsValueType || right.IsValueType)
442 {
443 return false;
444 }
445 if (!left.IsInterface && !right.IsInterface && !AreReferenceAssignable(left, right))
446 {
447 return AreReferenceAssignable(right, left);
448 }
449 return true;
450 }
451
452 public static bool HasBuiltInEqualityOperator(Type left, Type right)
453 {
454 if (left.IsInterface && !right.IsValueType)
455 {
456 return true;
457 }
458 if (right.IsInterface && !left.IsValueType)
459 {
460 return true;
461 }
462 if (!left.IsValueType && !right.IsValueType && (AreReferenceAssignable(left, right) || AreReferenceAssignable(right, left)))
463 {
464 return true;
465 }
466 if (!AreEquivalent(left, right))
467 {
468 return false;
469 }
470 Type nonNullableType = left.GetNonNullableType();
471 if (!(nonNullableType == typeof(bool)) && !nonNullableType.IsNumeric())
472 {
473 return nonNullableType.IsEnum;
474 }
475 return true;
476 }
477
486
487 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", Justification = "The trimmer doesn't remove operators when System.Linq.Expressions is used. See https://github.com/mono/linker/pull/2125.")]
488 public static MethodInfo GetUserDefinedCoercionMethod(Type convertFrom, Type convertToType)
489 {
490 Type nonNullableType = convertFrom.GetNonNullableType();
491 Type nonNullableType2 = convertToType.GetNonNullableType();
492 MethodInfo[] methods = nonNullableType.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
493 MethodInfo methodInfo = FindConversionOperator(methods, convertFrom, convertToType);
494 if (methodInfo != null)
495 {
496 return methodInfo;
497 }
498 MethodInfo[] methods2 = nonNullableType2.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
499 methodInfo = FindConversionOperator(methods2, convertFrom, convertToType);
500 if (methodInfo != null)
501 {
502 return methodInfo;
503 }
504 if (AreEquivalent(nonNullableType, convertFrom) && AreEquivalent(nonNullableType2, convertToType))
505 {
506 return null;
507 }
508 return FindConversionOperator(methods, nonNullableType, nonNullableType2) ?? FindConversionOperator(methods2, nonNullableType, nonNullableType2) ?? FindConversionOperator(methods, nonNullableType, convertToType) ?? FindConversionOperator(methods2, nonNullableType, convertToType);
509 }
510
511 private static MethodInfo FindConversionOperator(MethodInfo[] methods, Type typeFrom, Type typeTo)
512 {
513 foreach (MethodInfo methodInfo in methods)
514 {
515 if ((methodInfo.Name == "op_Implicit" || methodInfo.Name == "op_Explicit") && AreEquivalent(methodInfo.ReturnType, typeTo))
516 {
517 ParameterInfo[] parametersCached = methodInfo.GetParametersCached();
518 if (parametersCached.Length == 1 && AreEquivalent(parametersCached[0].ParameterType, typeFrom))
519 {
520 return methodInfo;
521 }
522 }
523 }
524 return null;
525 }
526
528 {
529 TypeCode typeCode = source.GetTypeCode();
530 TypeCode typeCode2 = destination.GetTypeCode();
531 switch (typeCode)
532 {
533 case TypeCode.SByte:
534 switch (typeCode2)
535 {
536 case TypeCode.Int16:
537 case TypeCode.Int32:
538 case TypeCode.Int64:
539 case TypeCode.Single:
540 case TypeCode.Double:
541 case TypeCode.Decimal:
542 return true;
543 }
544 break;
545 case TypeCode.Byte:
546 if ((uint)(typeCode2 - 7) <= 8u)
547 {
548 return true;
549 }
550 break;
551 case TypeCode.Int16:
552 switch (typeCode2)
553 {
554 case TypeCode.Int32:
555 case TypeCode.Int64:
556 case TypeCode.Single:
557 case TypeCode.Double:
558 case TypeCode.Decimal:
559 return true;
560 }
561 break;
562 case TypeCode.UInt16:
563 if ((uint)(typeCode2 - 9) <= 6u)
564 {
565 return true;
566 }
567 break;
568 case TypeCode.Int32:
569 if (typeCode2 == TypeCode.Int64 || (uint)(typeCode2 - 13) <= 2u)
570 {
571 return true;
572 }
573 break;
574 case TypeCode.UInt32:
575 if ((uint)(typeCode2 - 11) <= 4u)
576 {
577 return true;
578 }
579 break;
580 case TypeCode.Int64:
581 case TypeCode.UInt64:
582 if ((uint)(typeCode2 - 13) <= 2u)
583 {
584 return true;
585 }
586 break;
587 case TypeCode.Char:
588 if ((uint)(typeCode2 - 8) <= 7u)
589 {
590 return true;
591 }
592 break;
593 case TypeCode.Single:
594 return typeCode2 == TypeCode.Double;
595 }
596 return false;
597 }
598
600 {
601 return destination.IsAssignableFrom(source);
602 }
603
605 {
606 if (!source.IsValueType || (!(destination == typeof(object)) && !(destination == typeof(ValueType))))
607 {
608 if (source.IsEnum)
609 {
610 return destination == typeof(Enum);
611 }
612 return false;
613 }
614 return true;
615 }
616
618 {
619 if (destination.IsNullableType())
620 {
621 return source.GetNonNullableType().IsImplicitlyConvertibleTo(destination.GetNonNullableType());
622 }
623 return false;
624 }
625
626 public static Type FindGenericType(Type definition, Type type)
627 {
628 while ((object)type != null && type != typeof(object))
629 {
630 if (type.IsConstructedGenericType && AreEquivalent(type.GetGenericTypeDefinition(), definition))
631 {
632 return type;
633 }
634 type = type.BaseType;
635 }
636 return null;
637 }
638
639 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern", Justification = "The trimmer doesn't remove operators when System.Linq.Expressions is used. See https://github.com/mono/linker/pull/2125.")]
640 public static MethodInfo GetBooleanOperator(Type type, string name)
641 {
642 do
643 {
644 MethodInfo anyStaticMethodValidated = type.GetAnyStaticMethodValidated(name, new Type[1] { type });
645 if (anyStaticMethodValidated != null && anyStaticMethodValidated.IsSpecialName && !anyStaticMethodValidated.ContainsGenericParameters)
646 {
647 return anyStaticMethodValidated;
648 }
649 type = type.BaseType;
650 }
651 while (type != null);
652 return null;
653 }
654
655 public static Type GetNonRefType(this Type type)
656 {
657 if (!type.IsByRef)
658 {
659 return type;
660 }
661 return type.GetElementType();
662 }
663
664 public static bool AreEquivalent(Type t1, Type t2)
665 {
666 if (t1 != null)
667 {
668 return t1.IsEquivalentTo(t2);
669 }
670 return false;
671 }
672
673 public static bool AreReferenceAssignable(Type dest, Type src)
674 {
675 if (AreEquivalent(dest, src))
676 {
677 return true;
678 }
679 if (!dest.IsValueType && !src.IsValueType)
680 {
681 return dest.IsAssignableFrom(src);
682 }
683 return false;
684 }
685
686 public static bool IsSameOrSubclass(Type type, Type subType)
687 {
688 if (!AreEquivalent(type, subType))
689 {
690 return subType.IsSubclassOf(type);
691 }
692 return true;
693 }
694
695 public static void ValidateType(Type type, string paramName)
696 {
697 ValidateType(type, paramName, allowByRef: false, allowPointer: false);
698 }
699
700 public static void ValidateType(Type type, string paramName, bool allowByRef, bool allowPointer)
701 {
702 if (ValidateType(type, paramName, -1))
703 {
704 if (!allowByRef && type.IsByRef)
705 {
706 throw Error.TypeMustNotBeByRef(paramName);
707 }
708 if (!allowPointer && type.IsPointer)
709 {
710 throw Error.TypeMustNotBePointer(paramName);
711 }
712 }
713 }
714
715 public static bool ValidateType(Type type, string paramName, int index)
716 {
717 if (type == typeof(void))
718 {
719 return false;
720 }
721 if (type.ContainsGenericParameters)
722 {
723 throw type.IsGenericTypeDefinition ? Error.TypeIsGeneric(type, paramName, index) : Error.TypeContainsGenericParameters(type, paramName, index);
724 }
725 return true;
726 }
727
728 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", Justification = "The trimmer will never remove the Invoke method from delegates.")]
729 public static MethodInfo GetInvokeMethod(this Type delegateType)
730 {
731 return delegateType.GetMethod("Invoke", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
732 }
733
734 internal static bool IsUnsigned(this Type type)
735 {
736 return type.GetNonNullableType().GetTypeCode().IsUnsigned();
737 }
738
739 internal static bool IsUnsigned(this TypeCode typeCode)
740 {
741 switch (typeCode)
742 {
743 case TypeCode.Char:
744 case TypeCode.Byte:
745 case TypeCode.UInt16:
746 case TypeCode.UInt32:
747 case TypeCode.UInt64:
748 return true;
749 default:
750 return false;
751 }
752 }
753
754 internal static bool IsFloatingPoint(this Type type)
755 {
756 return type.GetNonNullableType().GetTypeCode().IsFloatingPoint();
757 }
758
759 internal static bool IsFloatingPoint(this TypeCode typeCode)
760 {
761 if ((uint)(typeCode - 13) <= 1u)
762 {
763 return true;
764 }
765 return false;
766 }
767
768 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", Justification = "The Array 'Get' method is dynamically constructed and is not included in IL. It is not subject to trimming.")]
769 public static MethodInfo GetArrayGetMethod(Type arrayType)
770 {
771 return arrayType.GetMethod("Get", BindingFlags.Instance | BindingFlags.Public);
772 }
773
774 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", Justification = "The Array 'Set' method is dynamically constructed and is not included in IL. It is not subject to trimming.")]
775 public static MethodInfo GetArraySetMethod(Type arrayType)
776 {
777 return arrayType.GetMethod("Set", BindingFlags.Instance | BindingFlags.Public);
778 }
779
780 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", Justification = "The Array 'Address' method is dynamically constructed and is not included in IL. It is not subject to trimming.")]
781 public static MethodInfo GetArrayAddressMethod(Type arrayType)
782 {
783 return arrayType.GetMethod("Address", BindingFlags.Instance | BindingFlags.Public);
784 }
785}
static bool IsInteger(this Type type)
Definition TypeUtils.cs:76
static bool IsDelegate(Type t)
Definition TypeUtils.cs:377
static bool HasReferenceEquality(Type left, Type right)
Definition TypeUtils.cs:439
static bool IsNullableType(this Type type)
Definition TypeUtils.cs:39
static bool IsNumericOrBool(this Type type)
Definition TypeUtils.cs:148
static ConstructorInfo GetNullableConstructor(Type nullableType)
Definition TypeUtils.cs:34
static bool IsSameOrSubclass(Type type, Type subType)
Definition TypeUtils.cs:686
static MethodInfo GetArrayGetMethod(Type arrayType)
Definition TypeUtils.cs:769
static bool StrictHasReferenceConversionTo(this Type source, Type dest, bool skipNonArray)
Definition TypeUtils.cs:262
static Type FindGenericType(Type definition, Type type)
Definition TypeUtils.cs:626
static bool IsUnsignedInt(this Type type)
Definition TypeUtils.cs:118
static bool HasBuiltInEqualityOperator(Type left, Type right)
Definition TypeUtils.cs:452
static bool IsFloatingPoint(this Type type)
Definition TypeUtils.cs:754
static bool IsImplicitNullableConversion(Type source, Type destination)
Definition TypeUtils.cs:617
static bool IsUnsigned(this Type type)
Definition TypeUtils.cs:734
static Type GetNonNullableType(this Type type)
Definition TypeUtils.cs:16
static void ValidateType(Type type, string paramName)
Definition TypeUtils.cs:695
static bool IsLegalExplicitVariantDelegateConversion(Type source, Type dest)
Definition TypeUtils.cs:382
static bool IsArithmetic(this Type type)
Definition TypeUtils.cs:104
static readonly ConstructorInfo s_nullableConstructor
Definition TypeUtils.cs:14
static bool IsImplicitReferenceConversion(Type source, Type destination)
Definition TypeUtils.cs:599
static bool IsIntegerOrBool(this Type type)
Definition TypeUtils.cs:134
static bool IsFloatingPoint(this TypeCode typeCode)
Definition TypeUtils.cs:759
static Type GetNonRefType(this Type type)
Definition TypeUtils.cs:655
static bool IsUnsigned(this TypeCode typeCode)
Definition TypeUtils.cs:739
static bool IsImplicitNumericConversion(Type source, Type destination)
Definition TypeUtils.cs:527
static bool AreEquivalent(Type t1, Type t2)
Definition TypeUtils.cs:664
static MethodInfo GetInvokeMethod(this Type delegateType)
Definition TypeUtils.cs:729
static bool IsCovariant(Type t)
Definition TypeUtils.cs:362
static bool IsNumeric(this Type type)
Definition TypeUtils.cs:62
static Type GetNullableType(this Type type)
Definition TypeUtils.cs:25
static bool ValidateType(Type type, string paramName, int index)
Definition TypeUtils.cs:715
static MethodInfo GetBooleanOperator(Type type, string name)
Definition TypeUtils.cs:640
static bool IsInteger64(this Type type)
Definition TypeUtils.cs:90
static bool IsImplicitlyConvertibleTo(this Type source, Type destination)
Definition TypeUtils.cs:478
static bool HasInterfaceToArrayConversion(Type source, Type dest)
Definition TypeUtils.cs:339
static void ValidateType(Type type, string paramName, bool allowByRef, bool allowPointer)
Definition TypeUtils.cs:700
static bool AreReferenceAssignable(Type dest, Type src)
Definition TypeUtils.cs:673
static bool IsBool(this Type type)
Definition TypeUtils.cs:57
static readonly Type[] s_arrayAssignableInterfaces
Definition TypeUtils.cs:10
static bool IsConvertible(this Type type)
Definition TypeUtils.cs:424
static bool IsImplicitBoxingConversion(Type source, Type destination)
Definition TypeUtils.cs:604
static MethodInfo FindConversionOperator(MethodInfo[] methods, Type typeFrom, Type typeTo)
Definition TypeUtils.cs:511
static bool IsNullableOrReferenceType(this Type type)
Definition TypeUtils.cs:48
static bool IsValidInstanceType(MemberInfo member, Type instanceType)
Definition TypeUtils.cs:157
static bool HasArrayToInterfaceConversion(Type source, Type dest)
Definition TypeUtils.cs:316
static MethodInfo GetArraySetMethod(Type arrayType)
Definition TypeUtils.cs:775
static bool IsContravariant(Type t)
Definition TypeUtils.cs:367
static bool HasReferenceConversionTo(this Type source, Type dest)
Definition TypeUtils.cs:231
static bool IsInvariant(Type t)
Definition TypeUtils.cs:372
static MethodInfo GetArrayAddressMethod(Type arrayType)
Definition TypeUtils.cs:781
static MethodInfo GetUserDefinedCoercionMethod(Type convertFrom, Type convertToType)
Definition TypeUtils.cs:488
static bool HasIdentityPrimitiveOrNullableConversionTo(this Type source, Type dest)
Definition TypeUtils.cs:202
static Exception TypeIsGeneric(object p0, string paramName)
Definition Error.cs:858
static Exception TypeContainsGenericParameters(object p0, string paramName)
Definition Error.cs:848
static Exception TypeMustNotBePointer(string paramName)
Definition Error.cs:143
static Exception TypeMustNotBeByRef(string paramName)
Definition Error.cs:138
virtual bool ContainsGenericParameters
Definition MethodBase.cs:82
Type? GetElementType()
bool IsInterface
Definition Type.cs:30
virtual bool IsAssignableFrom([NotNullWhen(true)] Type? c)
Definition Type.cs:1561
bool IsValueType
Definition Type.cs:234
bool IsClass
Definition Type.cs:184
virtual GenericParameterAttributes GenericParameterAttributes
Definition Type.cs:166
virtual Type[] GetGenericArguments()
Definition Type.cs:500
bool IsArray
Definition Type.cs:71
virtual MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberInfo member)
Definition Type.cs:649
virtual bool IsEnum
Definition Type.cs:227
virtual int GetArrayRank()
Definition Type.cs:490
virtual bool IsGenericType
Definition Type.cs:111
virtual bool IsSZArray
Definition Type.cs:116
virtual bool IsEquivalentTo([NotNullWhen(true)] Type? other)
Definition Type.cs:1029
virtual bool IsSubclassOf(Type c)
Definition Type.cs:1542
Type[] GetInterfaces()
MethodInfo[] GetMethods()
Definition Type.cs:788
MethodInfo? GetMethod(string name)
Definition Type.cs:675
virtual Type GetGenericTypeDefinition()
Definition Type.cs:495
bool IsSealed
Definition Type.cs:179
TypeCode
Definition TypeCode.cs:4