Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ILGen.cs
Go to the documentation of this file.
5
7
8internal static class ILGen
9{
10 private static readonly MethodInfo s_nullableHasValueGetter = typeof(Nullable<>).GetMethod("get_HasValue", BindingFlags.Instance | BindingFlags.Public);
11
12 private static readonly MethodInfo s_nullableValueGetter = typeof(Nullable<>).GetMethod("get_Value", BindingFlags.Instance | BindingFlags.Public);
13
14 private static readonly MethodInfo s_nullableGetValueOrDefault = typeof(Nullable<>).GetMethod("GetValueOrDefault", Type.EmptyTypes);
15
16 internal static void Emit(this ILGenerator il, OpCode opcode, MethodBase methodBase)
17 {
18 if (methodBase is ConstructorInfo con)
19 {
20 il.Emit(opcode, con);
21 }
22 else
23 {
24 il.Emit(opcode, (MethodInfo)methodBase);
25 }
26 }
27
28 internal static void EmitLoadArg(this ILGenerator il, int index)
29 {
31 }
32
33 internal static void EmitLoadArgAddress(this ILGenerator il, int index)
34 {
36 }
37
38 internal static void EmitStoreArg(this ILGenerator il, int index)
39 {
41 }
42
43 internal static void EmitLoadValueIndirect(this ILGenerator il, Type type)
44 {
45 switch (type.GetTypeCode())
46 {
47 case TypeCode.SByte:
49 return;
50 case TypeCode.Boolean:
51 case TypeCode.Byte:
53 return;
54 case TypeCode.Int16:
56 return;
57 case TypeCode.Char:
58 case TypeCode.UInt16:
60 return;
61 case TypeCode.Int32:
63 return;
64 case TypeCode.UInt32:
66 return;
67 case TypeCode.Int64:
68 case TypeCode.UInt64:
70 return;
71 case TypeCode.Single:
73 return;
74 case TypeCode.Double:
76 return;
77 }
78 if (type.IsValueType)
79 {
81 }
82 else
83 {
85 }
86 }
87
88 internal static void EmitStoreValueIndirect(this ILGenerator il, Type type)
89 {
90 switch (type.GetTypeCode())
91 {
92 case TypeCode.Boolean:
93 case TypeCode.SByte:
94 case TypeCode.Byte:
96 return;
97 case TypeCode.Char:
98 case TypeCode.Int16:
99 case TypeCode.UInt16:
101 return;
102 case TypeCode.Int32:
103 case TypeCode.UInt32:
105 return;
106 case TypeCode.Int64:
107 case TypeCode.UInt64:
109 return;
110 case TypeCode.Single:
112 return;
113 case TypeCode.Double:
115 return;
116 }
117 if (type.IsValueType)
118 {
119 il.Emit(OpCodes.Stobj, type);
120 }
121 else
122 {
124 }
125 }
126
127 internal static void EmitLoadElement(this ILGenerator il, Type type)
128 {
129 if (!type.IsValueType)
130 {
132 return;
133 }
134 switch (type.GetTypeCode())
135 {
136 case TypeCode.Boolean:
137 case TypeCode.SByte:
139 break;
140 case TypeCode.Byte:
142 break;
143 case TypeCode.Int16:
145 break;
146 case TypeCode.Char:
147 case TypeCode.UInt16:
149 break;
150 case TypeCode.Int32:
152 break;
153 case TypeCode.UInt32:
155 break;
156 case TypeCode.Int64:
157 case TypeCode.UInt64:
159 break;
160 case TypeCode.Single:
162 break;
163 case TypeCode.Double:
165 break;
166 default:
167 il.Emit(OpCodes.Ldelem, type);
168 break;
169 }
170 }
171
172 internal static void EmitStoreElement(this ILGenerator il, Type type)
173 {
174 switch (type.GetTypeCode())
175 {
176 case TypeCode.Boolean:
177 case TypeCode.SByte:
178 case TypeCode.Byte:
180 return;
181 case TypeCode.Char:
182 case TypeCode.Int16:
183 case TypeCode.UInt16:
185 return;
186 case TypeCode.Int32:
187 case TypeCode.UInt32:
189 return;
190 case TypeCode.Int64:
191 case TypeCode.UInt64:
193 return;
194 case TypeCode.Single:
196 return;
197 case TypeCode.Double:
199 return;
200 }
201 if (type.IsValueType)
202 {
203 il.Emit(OpCodes.Stelem, type);
204 }
205 else
206 {
208 }
209 }
210
211 internal static void EmitType(this ILGenerator il, Type type)
212 {
215 }
216
217 internal static void EmitFieldAddress(this ILGenerator il, FieldInfo fi)
218 {
219 il.Emit(fi.IsStatic ? OpCodes.Ldsflda : OpCodes.Ldflda, fi);
220 }
221
222 internal static void EmitFieldGet(this ILGenerator il, FieldInfo fi)
223 {
224 il.Emit(fi.IsStatic ? OpCodes.Ldsfld : OpCodes.Ldfld, fi);
225 }
226
227 internal static void EmitFieldSet(this ILGenerator il, FieldInfo fi)
228 {
229 il.Emit(fi.IsStatic ? OpCodes.Stsfld : OpCodes.Stfld, fi);
230 }
231
232 internal static void EmitNew(this ILGenerator il, ConstructorInfo ci)
233 {
234 il.Emit(OpCodes.Newobj, ci);
235 }
236
237 internal static void EmitNull(this ILGenerator il)
238 {
239 il.Emit(OpCodes.Ldnull);
240 }
241
242 internal static void EmitString(this ILGenerator il, string value)
243 {
244 il.Emit(OpCodes.Ldstr, value);
245 }
246
247 internal static void EmitPrimitive(this ILGenerator il, bool value)
248 {
250 }
251
252 internal static void EmitPrimitive(this ILGenerator il, int value)
253 {
255 }
256
257 private static void EmitPrimitive(this ILGenerator il, uint value)
258 {
259 il.EmitPrimitive((int)value);
260 }
261
262 private static void EmitPrimitive(this ILGenerator il, long value)
263 {
264 if (int.MinValue <= value && value <= uint.MaxValue)
265 {
266 il.EmitPrimitive((int)value);
267 il.Emit((value > 0) ? OpCodes.Conv_U8 : OpCodes.Conv_I8);
268 }
269 else
270 {
272 }
273 }
274
275 private static void EmitPrimitive(this ILGenerator il, ulong value)
276 {
277 il.EmitPrimitive((long)value);
278 }
279
280 private static void EmitPrimitive(this ILGenerator il, double value)
281 {
283 }
284
285 private static void EmitPrimitive(this ILGenerator il, float value)
286 {
288 }
289
290 internal static bool CanEmitConstant(object value, Type type)
291 {
292 if (value == null || CanEmitILConstant(type))
293 {
294 return true;
295 }
296 if (value is Type t)
297 {
298 return ShouldLdtoken(t);
299 }
300 if (value is MethodBase mb)
301 {
302 return ShouldLdtoken(mb);
303 }
304 return false;
305 }
306
307 private static bool CanEmitILConstant(Type type)
308 {
309 TypeCode typeCode = type.GetNonNullableType().GetTypeCode();
310 if ((uint)(typeCode - 3) <= 12u || typeCode == TypeCode.String)
311 {
312 return true;
313 }
314 return false;
315 }
316
317 internal static bool TryEmitConstant(this ILGenerator il, object value, Type type, ILocalCache locals)
318 {
319 if (value == null)
320 {
321 il.EmitDefault(type, locals);
322 return true;
323 }
324 if (il.TryEmitILConstant(value, type))
325 {
326 return true;
327 }
328 if (value is Type type2)
329 {
330 if (ShouldLdtoken(type2))
331 {
332 il.EmitType(type2);
333 if (type != typeof(Type))
334 {
336 }
337 return true;
338 }
339 return false;
340 }
341 if (value is MethodBase methodBase && ShouldLdtoken(methodBase))
342 {
343 il.Emit(OpCodes.Ldtoken, methodBase);
344 Type declaringType = methodBase.DeclaringType;
345 if (declaringType != null && declaringType.IsGenericType)
346 {
347 il.Emit(OpCodes.Ldtoken, declaringType);
349 }
350 else
351 {
353 }
354 if (type != typeof(MethodBase))
355 {
357 }
358 return true;
359 }
360 return false;
361 }
362
363 private static bool ShouldLdtoken(Type t)
364 {
365 if (!t.IsGenericParameter)
366 {
367 return t.IsVisible;
368 }
369 return true;
370 }
371
372 internal static bool ShouldLdtoken(MethodBase mb)
373 {
374 if (mb is DynamicMethod)
375 {
376 return false;
377 }
378 Type declaringType = mb.DeclaringType;
379 if (!(declaringType == null))
380 {
381 return ShouldLdtoken(declaringType);
382 }
383 return true;
384 }
385
386 private static bool TryEmitILConstant(this ILGenerator il, object value, Type type)
387 {
388 if (type.IsNullableType())
389 {
390 Type nonNullableType = type.GetNonNullableType();
391 if (il.TryEmitILConstant(value, nonNullableType))
392 {
394 return true;
395 }
396 return false;
397 }
398 switch (type.GetTypeCode())
399 {
400 case TypeCode.Boolean:
401 il.EmitPrimitive((bool)value);
402 return true;
403 case TypeCode.SByte:
404 il.EmitPrimitive((sbyte)value);
405 return true;
406 case TypeCode.Int16:
407 il.EmitPrimitive((short)value);
408 return true;
409 case TypeCode.Int32:
410 il.EmitPrimitive((int)value);
411 return true;
412 case TypeCode.Int64:
413 il.EmitPrimitive((long)value);
414 return true;
415 case TypeCode.Single:
416 il.EmitPrimitive((float)value);
417 return true;
418 case TypeCode.Double:
419 il.EmitPrimitive((double)value);
420 return true;
421 case TypeCode.Char:
422 il.EmitPrimitive((char)value);
423 return true;
424 case TypeCode.Byte:
425 il.EmitPrimitive((byte)value);
426 return true;
427 case TypeCode.UInt16:
428 il.EmitPrimitive((ushort)value);
429 return true;
430 case TypeCode.UInt32:
431 il.EmitPrimitive((uint)value);
432 return true;
433 case TypeCode.UInt64:
434 il.EmitPrimitive((ulong)value);
435 return true;
436 case TypeCode.Decimal:
437 il.EmitDecimal((decimal)value);
438 return true;
439 case TypeCode.String:
440 il.EmitString((string)value);
441 return true;
442 default:
443 return false;
444 }
445 }
446
447 internal static void EmitConvertToType(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
448 {
449 if (!TypeUtils.AreEquivalent(typeFrom, typeTo))
450 {
451 bool flag = typeFrom.IsNullableType();
452 bool flag2 = typeTo.IsNullableType();
453 Type nonNullableType = typeFrom.GetNonNullableType();
454 Type nonNullableType2 = typeTo.GetNonNullableType();
455 if (typeFrom.IsInterface || typeTo.IsInterface || typeFrom == typeof(object) || typeTo == typeof(object) || typeFrom == typeof(Enum) || typeFrom == typeof(ValueType) || TypeUtils.IsLegalExplicitVariantDelegateConversion(typeFrom, typeTo))
456 {
457 il.EmitCastToType(typeFrom, typeTo);
458 }
459 else if (flag || flag2)
460 {
461 il.EmitNullableConversion(typeFrom, typeTo, isChecked, locals);
462 }
463 else if ((!typeFrom.IsConvertible() || !typeTo.IsConvertible()) && (nonNullableType.IsAssignableFrom(nonNullableType2) || nonNullableType2.IsAssignableFrom(nonNullableType)))
464 {
465 il.EmitCastToType(typeFrom, typeTo);
466 }
467 else if (typeFrom.IsArray && typeTo.IsArray)
468 {
469 il.EmitCastToType(typeFrom, typeTo);
470 }
471 else
472 {
473 il.EmitNumericConversion(typeFrom, typeTo, isChecked);
474 }
475 }
476 }
477
478 private static void EmitCastToType(this ILGenerator il, Type typeFrom, Type typeTo)
479 {
480 if (typeFrom.IsValueType)
481 {
482 il.Emit(OpCodes.Box, typeFrom);
483 if (typeTo != typeof(object))
484 {
485 il.Emit(OpCodes.Castclass, typeTo);
486 }
487 }
488 else
489 {
490 il.Emit(typeTo.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass, typeTo);
491 }
492 }
493
494 private static void EmitNumericConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked)
495 {
496 TypeCode typeCode = typeTo.GetTypeCode();
497 TypeCode typeCode2 = typeFrom.GetTypeCode();
498 if (typeCode == typeCode2)
499 {
500 return;
501 }
502 bool flag = typeCode2.IsUnsigned();
503 OpCode opcode;
504 switch (typeCode)
505 {
506 case TypeCode.Single:
507 if (flag)
508 {
510 }
511 opcode = OpCodes.Conv_R4;
512 break;
513 case TypeCode.Double:
514 if (flag)
515 {
517 }
518 opcode = OpCodes.Conv_R8;
519 break;
520 case TypeCode.Decimal:
521 {
522 MethodInfo meth = typeCode2 switch
523 {
533 _ => throw ContractUtils.Unreachable,
534 };
535 il.Emit(OpCodes.Call, meth);
536 return;
537 }
538 case TypeCode.SByte:
539 if (isChecked)
540 {
541 opcode = (flag ? OpCodes.Conv_Ovf_I1_Un : OpCodes.Conv_Ovf_I1);
542 break;
543 }
544 if (typeCode2 == TypeCode.Byte)
545 {
546 return;
547 }
548 opcode = OpCodes.Conv_I1;
549 break;
550 case TypeCode.Byte:
551 if (isChecked)
552 {
553 opcode = (flag ? OpCodes.Conv_Ovf_U1_Un : OpCodes.Conv_Ovf_U1);
554 break;
555 }
556 if (typeCode2 == TypeCode.SByte)
557 {
558 return;
559 }
560 opcode = OpCodes.Conv_U1;
561 break;
562 case TypeCode.Int16:
563 switch (typeCode2)
564 {
565 case TypeCode.SByte:
566 case TypeCode.Byte:
567 return;
568 case TypeCode.Char:
569 case TypeCode.UInt16:
570 if (!isChecked)
571 {
572 return;
573 }
574 break;
575 }
576 opcode = ((!isChecked) ? OpCodes.Conv_I2 : (flag ? OpCodes.Conv_Ovf_I2_Un : OpCodes.Conv_Ovf_I2));
577 break;
578 case TypeCode.Char:
579 case TypeCode.UInt16:
580 switch (typeCode2)
581 {
582 case TypeCode.Char:
583 case TypeCode.Byte:
584 case TypeCode.UInt16:
585 return;
586 case TypeCode.SByte:
587 case TypeCode.Int16:
588 if (!isChecked)
589 {
590 return;
591 }
592 break;
593 }
594 opcode = ((!isChecked) ? OpCodes.Conv_U2 : (flag ? OpCodes.Conv_Ovf_U2_Un : OpCodes.Conv_Ovf_U2));
595 break;
596 case TypeCode.Int32:
597 switch (typeCode2)
598 {
599 case TypeCode.SByte:
600 case TypeCode.Byte:
601 case TypeCode.Int16:
602 case TypeCode.UInt16:
603 return;
604 case TypeCode.UInt32:
605 if (!isChecked)
606 {
607 return;
608 }
609 break;
610 }
611 opcode = ((!isChecked) ? OpCodes.Conv_I4 : (flag ? OpCodes.Conv_Ovf_I4_Un : OpCodes.Conv_Ovf_I4));
612 break;
613 case TypeCode.UInt32:
614 switch (typeCode2)
615 {
616 case TypeCode.Char:
617 case TypeCode.Byte:
618 case TypeCode.UInt16:
619 return;
620 case TypeCode.SByte:
621 case TypeCode.Int16:
622 case TypeCode.Int32:
623 if (!isChecked)
624 {
625 return;
626 }
627 break;
628 }
629 opcode = ((!isChecked) ? OpCodes.Conv_U4 : (flag ? OpCodes.Conv_Ovf_U4_Un : OpCodes.Conv_Ovf_U4));
630 break;
631 case TypeCode.Int64:
632 if (!isChecked && typeCode2 == TypeCode.UInt64)
633 {
634 return;
635 }
636 opcode = ((!isChecked) ? (flag ? OpCodes.Conv_U8 : OpCodes.Conv_I8) : (flag ? OpCodes.Conv_Ovf_I8_Un : OpCodes.Conv_Ovf_I8));
637 break;
638 case TypeCode.UInt64:
639 if (!isChecked && typeCode2 == TypeCode.Int64)
640 {
641 return;
642 }
643 opcode = ((!isChecked) ? ((flag || typeCode2.IsFloatingPoint()) ? OpCodes.Conv_U8 : OpCodes.Conv_I8) : ((flag || typeCode2.IsFloatingPoint()) ? OpCodes.Conv_Ovf_U8_Un : OpCodes.Conv_Ovf_U8));
644 break;
645 default:
647 }
648 il.Emit(opcode);
649 }
650
651 private static void EmitNullableToNullableConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
652 {
653 LocalBuilder local = locals.GetLocal(typeFrom);
654 il.Emit(OpCodes.Stloc, local);
655 il.Emit(OpCodes.Ldloca, local);
656 il.EmitHasValue(typeFrom);
657 Label label = il.DefineLabel();
658 il.Emit(OpCodes.Brfalse_S, label);
659 il.Emit(OpCodes.Ldloca, local);
660 locals.FreeLocal(local);
661 il.EmitGetValueOrDefault(typeFrom);
662 Type nonNullableType = typeFrom.GetNonNullableType();
663 Type nonNullableType2 = typeTo.GetNonNullableType();
664 il.EmitConvertToType(nonNullableType, nonNullableType2, isChecked, locals);
665 ConstructorInfo nullableConstructor = TypeUtils.GetNullableConstructor(typeTo);
666 il.Emit(OpCodes.Newobj, nullableConstructor);
667 Label label2 = il.DefineLabel();
668 il.Emit(OpCodes.Br_S, label2);
669 il.MarkLabel(label);
670 LocalBuilder local2 = locals.GetLocal(typeTo);
671 il.Emit(OpCodes.Ldloca, local2);
672 il.Emit(OpCodes.Initobj, typeTo);
673 il.Emit(OpCodes.Ldloc, local2);
674 locals.FreeLocal(local2);
675 il.MarkLabel(label2);
676 }
677
678 private static void EmitNonNullableToNullableConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
679 {
680 Type nonNullableType = typeTo.GetNonNullableType();
681 il.EmitConvertToType(typeFrom, nonNullableType, isChecked, locals);
682 ConstructorInfo nullableConstructor = TypeUtils.GetNullableConstructor(typeTo);
683 il.Emit(OpCodes.Newobj, nullableConstructor);
684 }
685
686 private static void EmitNullableToNonNullableConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
687 {
688 if (typeTo.IsValueType)
689 {
690 il.EmitNullableToNonNullableStructConversion(typeFrom, typeTo, isChecked, locals);
691 }
692 else
693 {
694 il.EmitNullableToReferenceConversion(typeFrom);
695 }
696 }
697
698 private static void EmitNullableToNonNullableStructConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
699 {
700 LocalBuilder local = locals.GetLocal(typeFrom);
701 il.Emit(OpCodes.Stloc, local);
702 il.Emit(OpCodes.Ldloca, local);
703 locals.FreeLocal(local);
704 il.EmitGetValue(typeFrom);
705 Type nonNullableType = typeFrom.GetNonNullableType();
706 il.EmitConvertToType(nonNullableType, typeTo, isChecked, locals);
707 }
708
709 private static void EmitNullableToReferenceConversion(this ILGenerator il, Type typeFrom)
710 {
711 il.Emit(OpCodes.Box, typeFrom);
712 }
713
714 private static void EmitNullableConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
715 {
716 bool flag = typeFrom.IsNullableType();
717 bool flag2 = typeTo.IsNullableType();
718 if (flag && flag2)
719 {
720 il.EmitNullableToNullableConversion(typeFrom, typeTo, isChecked, locals);
721 }
722 else if (flag)
723 {
724 il.EmitNullableToNonNullableConversion(typeFrom, typeTo, isChecked, locals);
725 }
726 else
727 {
728 il.EmitNonNullableToNullableConversion(typeFrom, typeTo, isChecked, locals);
729 }
730 }
731
732 internal static void EmitHasValue(this ILGenerator il, Type nullableType)
733 {
735 il.Emit(OpCodes.Call, meth);
736 }
737
738 internal static void EmitGetValue(this ILGenerator il, Type nullableType)
739 {
741 il.Emit(OpCodes.Call, meth);
742 }
743
744 internal static void EmitGetValueOrDefault(this ILGenerator il, Type nullableType)
745 {
747 il.Emit(OpCodes.Call, meth);
748 }
749
750 internal static void EmitArray(this ILGenerator il, Type elementType, int count)
751 {
752 il.EmitPrimitive(count);
754 }
755
756 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", Justification = "The Array ctor is dynamically constructed and is not included in IL. It is not subject to trimming.")]
757 internal static void EmitArray(this ILGenerator il, Type arrayType)
758 {
759 if (arrayType.IsSZArray)
760 {
761 il.Emit(OpCodes.Newarr, arrayType.GetElementType());
762 return;
763 }
764 Type[] array = new Type[arrayType.GetArrayRank()];
765 for (int i = 0; i < array.Length; i++)
766 {
767 array[i] = typeof(int);
768 }
769 ConstructorInfo constructor = arrayType.GetConstructor(array);
770 il.EmitNew(constructor);
771 }
772
773 private static void EmitDecimal(this ILGenerator il, decimal value)
774 {
775 Span<int> destination = stackalloc int[4];
776 decimal.GetBits(value, destination);
777 int num = (destination[3] & 0x7FFFFFFF) >> 16;
778 if (num == 0)
779 {
780 if (-2147483648m <= value)
781 {
782 if (value <= 2147483647m)
783 {
784 int num2 = decimal.ToInt32(value);
785 switch (num2)
786 {
787 case -1:
789 break;
790 case 0:
791 il.EmitDefault(typeof(decimal), null);
792 break;
793 case 1:
795 break;
796 default:
797 il.EmitPrimitive(num2);
799 break;
800 }
801 return;
802 }
803 if (value <= 4294967295m)
804 {
805 il.EmitPrimitive(decimal.ToUInt32(value));
807 return;
808 }
809 }
810 if (-9223372036854775808m <= value)
811 {
812 if (value <= 9223372036854775807m)
813 {
814 il.EmitPrimitive(decimal.ToInt64(value));
816 return;
817 }
818 if (value <= 18446744073709551615m)
819 {
820 il.EmitPrimitive(decimal.ToUInt64(value));
822 return;
823 }
824 if (value == decimal.MaxValue)
825 {
827 return;
828 }
829 }
830 else if (value == decimal.MinValue)
831 {
833 return;
834 }
835 }
836 il.EmitPrimitive(destination[0]);
837 il.EmitPrimitive(destination[1]);
838 il.EmitPrimitive(destination[2]);
839 il.EmitPrimitive((destination[3] & 0x80000000u) != 0);
840 il.EmitPrimitive((byte)num);
842 }
843
844 internal static void EmitDefault(this ILGenerator il, Type type, ILocalCache locals)
845 {
846 switch (type.GetTypeCode())
847 {
848 case TypeCode.DateTime:
850 break;
851 case TypeCode.Object:
852 if (type.IsValueType)
853 {
854 LocalBuilder local = locals.GetLocal(type);
855 il.Emit(OpCodes.Ldloca, local);
857 il.Emit(OpCodes.Ldloc, local);
858 locals.FreeLocal(local);
859 break;
860 }
861 goto case TypeCode.Empty;
862 case TypeCode.Empty:
863 case TypeCode.DBNull:
864 case TypeCode.String:
865 il.Emit(OpCodes.Ldnull);
866 break;
867 case TypeCode.Boolean:
868 case TypeCode.Char:
869 case TypeCode.SByte:
870 case TypeCode.Byte:
871 case TypeCode.Int16:
872 case TypeCode.UInt16:
873 case TypeCode.Int32:
874 case TypeCode.UInt32:
876 break;
877 case TypeCode.Int64:
878 case TypeCode.UInt64:
880 il.Emit(OpCodes.Conv_I8);
881 break;
882 case TypeCode.Single:
883 il.Emit(OpCodes.Ldc_R4, 0f);
884 break;
885 case TypeCode.Double:
886 il.Emit(OpCodes.Ldc_R8, 0.0);
887 break;
888 case TypeCode.Decimal:
890 break;
891 default:
893 }
894 }
895}
static ConstructorInfo GetNullableConstructor(Type nullableType)
Definition TypeUtils.cs:34
static bool IsLegalExplicitVariantDelegateConversion(Type source, Type dest)
Definition TypeUtils.cs:382
static bool AreEquivalent(Type t1, Type t2)
Definition TypeUtils.cs:664
static MethodInfo MethodBase_GetMethodFromHandle_RuntimeMethodHandle_RuntimeTypeHandle
static void EmitNullableConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
Definition ILGen.cs:714
static void EmitArray(this ILGenerator il, Type elementType, int count)
Definition ILGen.cs:750
static void EmitNullableToNonNullableStructConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
Definition ILGen.cs:698
static bool ShouldLdtoken(MethodBase mb)
Definition ILGen.cs:372
static void EmitNullableToReferenceConversion(this ILGenerator il, Type typeFrom)
Definition ILGen.cs:709
static void EmitCastToType(this ILGenerator il, Type typeFrom, Type typeTo)
Definition ILGen.cs:478
static void EmitGetValueOrDefault(this ILGenerator il, Type nullableType)
Definition ILGen.cs:744
static void EmitType(this ILGenerator il, Type type)
Definition ILGen.cs:211
static void EmitNumericConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked)
Definition ILGen.cs:494
static bool TryEmitILConstant(this ILGenerator il, object value, Type type)
Definition ILGen.cs:386
static void EmitLoadArgAddress(this ILGenerator il, int index)
Definition ILGen.cs:33
static void EmitGetValue(this ILGenerator il, Type nullableType)
Definition ILGen.cs:738
static bool TryEmitConstant(this ILGenerator il, object value, Type type, ILocalCache locals)
Definition ILGen.cs:317
static void EmitFieldAddress(this ILGenerator il, FieldInfo fi)
Definition ILGen.cs:217
static void Emit(this ILGenerator il, OpCode opcode, MethodBase methodBase)
Definition ILGen.cs:16
static bool CanEmitILConstant(Type type)
Definition ILGen.cs:307
static void EmitPrimitive(this ILGenerator il, double value)
Definition ILGen.cs:280
static void EmitFieldGet(this ILGenerator il, FieldInfo fi)
Definition ILGen.cs:222
static void EmitDecimal(this ILGenerator il, decimal value)
Definition ILGen.cs:773
static void EmitStoreValueIndirect(this ILGenerator il, Type type)
Definition ILGen.cs:88
static bool CanEmitConstant(object value, Type type)
Definition ILGen.cs:290
static void EmitNull(this ILGenerator il)
Definition ILGen.cs:237
static void EmitHasValue(this ILGenerator il, Type nullableType)
Definition ILGen.cs:732
static void EmitLoadValueIndirect(this ILGenerator il, Type type)
Definition ILGen.cs:43
static bool ShouldLdtoken(Type t)
Definition ILGen.cs:363
static void EmitNullableToNullableConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
Definition ILGen.cs:651
static void EmitLoadArg(this ILGenerator il, int index)
Definition ILGen.cs:28
static void EmitArray(this ILGenerator il, Type arrayType)
Definition ILGen.cs:757
static void EmitNullableToNonNullableConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
Definition ILGen.cs:686
static void EmitConvertToType(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
Definition ILGen.cs:447
static readonly MethodInfo s_nullableHasValueGetter
Definition ILGen.cs:10
static void EmitPrimitive(this ILGenerator il, bool value)
Definition ILGen.cs:247
static void EmitString(this ILGenerator il, string value)
Definition ILGen.cs:242
static void EmitPrimitive(this ILGenerator il, ulong value)
Definition ILGen.cs:275
static void EmitDefault(this ILGenerator il, Type type, ILocalCache locals)
Definition ILGen.cs:844
static void EmitNonNullableToNullableConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked, ILocalCache locals)
Definition ILGen.cs:678
static readonly MethodInfo s_nullableGetValueOrDefault
Definition ILGen.cs:14
static void EmitLoadElement(this ILGenerator il, Type type)
Definition ILGen.cs:127
static readonly MethodInfo s_nullableValueGetter
Definition ILGen.cs:12
static void EmitPrimitive(this ILGenerator il, float value)
Definition ILGen.cs:285
static void EmitFieldSet(this ILGenerator il, FieldInfo fi)
Definition ILGen.cs:227
static void EmitStoreElement(this ILGenerator il, Type type)
Definition ILGen.cs:172
static void EmitPrimitive(this ILGenerator il, long value)
Definition ILGen.cs:262
static void EmitPrimitive(this ILGenerator il, int value)
Definition ILGen.cs:252
static void EmitStoreArg(this ILGenerator il, int index)
Definition ILGen.cs:38
static void EmitPrimitive(this ILGenerator il, uint value)
Definition ILGen.cs:257
static void EmitNew(this ILGenerator il, ConstructorInfo ci)
Definition ILGen.cs:232
virtual void MarkLabel(Label loc)
virtual void Emit(OpCode opcode)
static readonly OpCode Castclass
Definition OpCodes.cs:235
static readonly OpCode Ldloca
Definition OpCodes.cs:427
static readonly OpCode Ldelem_I2
Definition OpCodes.cs:291
static readonly OpCode Ldelem_U2
Definition OpCodes.cs:293
static readonly OpCode Stind_R8
Definition OpCodes.cs:177
static readonly OpCode Conv_I4
Definition OpCodes.cs:213
static readonly OpCode Stind_I1
Definition OpCodes.cs:167
static readonly OpCode Unbox_Any
Definition OpCodes.cs:329
static readonly OpCode Ldsflda
Definition OpCodes.cs:253
static readonly OpCode Ldc_I8
Definition OpCodes.cs:71
static readonly OpCode Conv_R_Un
Definition OpCodes.cs:239
static readonly OpCode Ldind_I1
Definition OpCodes.cs:143
static readonly OpCode Br_S
Definition OpCodes.cs:89
static readonly OpCode Conv_I2
Definition OpCodes.cs:211
static readonly OpCode Stind_I2
Definition OpCodes.cs:169
static readonly OpCode Stloc
Definition OpCodes.cs:429
static readonly OpCode Ldind_R4
Definition OpCodes.cs:159
static readonly OpCode Conv_Ovf_U1
Definition OpCodes.cs:333
static readonly OpCode Conv_Ovf_I1
Definition OpCodes.cs:331
static readonly OpCode Ldind_I2
Definition OpCodes.cs:147
static readonly OpCode Newobj
Definition OpCodes.cs:233
static readonly OpCode Ldind_I4
Definition OpCodes.cs:151
static readonly OpCode Ldflda
Definition OpCodes.cs:247
static readonly OpCode Ldind_U2
Definition OpCodes.cs:149
static readonly OpCode Ldelem
Definition OpCodes.cs:325
static readonly OpCode Conv_I1
Definition OpCodes.cs:209
static readonly OpCode Ldind_U4
Definition OpCodes.cs:153
static readonly OpCode Ldelem_U4
Definition OpCodes.cs:297
static readonly OpCode Ldind_R8
Definition OpCodes.cs:161
static readonly OpCode Ldind_I8
Definition OpCodes.cs:155
static readonly OpCode Stind_I8
Definition OpCodes.cs:173
static readonly OpCode Ldobj
Definition OpCodes.cs:229
static readonly OpCode Ldc_I4
Definition OpCodes.cs:69
static readonly OpCode Stelem_Ref
Definition OpCodes.cs:323
static readonly OpCode Stsfld
Definition OpCodes.cs:255
static readonly OpCode Conv_Ovf_I2
Definition OpCodes.cs:335
static readonly OpCode Conv_Ovf_I8
Definition OpCodes.cs:343
static readonly OpCode Initobj
Definition OpCodes.cs:441
static readonly OpCode Conv_U1
Definition OpCodes.cs:357
static readonly OpCode Stelem_I4
Definition OpCodes.cs:315
static readonly OpCode Conv_Ovf_U8
Definition OpCodes.cs:345
static readonly OpCode Ldfld
Definition OpCodes.cs:245
static readonly OpCode Stind_I4
Definition OpCodes.cs:171
static readonly OpCode Ldarga
Definition OpCodes.cs:421
static readonly OpCode Conv_U4
Definition OpCodes.cs:221
static readonly OpCode Ldelem_Ref
Definition OpCodes.cs:307
static readonly OpCode Ldc_I4_1
Definition OpCodes.cs:51
static readonly OpCode Ldc_I4_0
Definition OpCodes.cs:49
static readonly OpCode Stelem_I8
Definition OpCodes.cs:317
static readonly OpCode Conv_Ovf_U8_Un
Definition OpCodes.cs:273
static readonly OpCode Ldstr
Definition OpCodes.cs:231
static readonly OpCode Conv_R4
Definition OpCodes.cs:217
static readonly OpCode Conv_U2
Definition OpCodes.cs:355
static readonly OpCode Stobj
Definition OpCodes.cs:257
static readonly OpCode Ldind_U1
Definition OpCodes.cs:145
static readonly OpCode Ldsfld
Definition OpCodes.cs:251
static readonly OpCode Stelem_I1
Definition OpCodes.cs:311
static readonly OpCode Ldelem_I4
Definition OpCodes.cs:295
static readonly OpCode Ldelem_R4
Definition OpCodes.cs:303
static readonly OpCode Ldelem_U1
Definition OpCodes.cs:289
static readonly OpCode Ldtoken
Definition OpCodes.cs:353
static readonly OpCode Call
Definition OpCodes.cs:83
static readonly OpCode Stelem
Definition OpCodes.cs:327
static readonly OpCode Stelem_R4
Definition OpCodes.cs:319
static readonly OpCode Conv_R8
Definition OpCodes.cs:219
static readonly OpCode Ldloc
Definition OpCodes.cs:425
static readonly OpCode Ldnull
Definition OpCodes.cs:45
static readonly OpCode Conv_Ovf_I4
Definition OpCodes.cs:339
static readonly OpCode Stind_R4
Definition OpCodes.cs:175
static readonly OpCode Brfalse_S
Definition OpCodes.cs:91
static readonly OpCode Ldc_R4
Definition OpCodes.cs:73
static readonly OpCode Starg
Definition OpCodes.cs:423
static readonly OpCode Box
Definition OpCodes.cs:279
static readonly OpCode Conv_Ovf_U4
Definition OpCodes.cs:341
static readonly OpCode Ldind_Ref
Definition OpCodes.cs:163
static readonly OpCode Conv_U8
Definition OpCodes.cs:223
static readonly OpCode Ldc_R8
Definition OpCodes.cs:75
static readonly OpCode Stelem_I2
Definition OpCodes.cs:313
static readonly OpCode Conv_Ovf_U2
Definition OpCodes.cs:337
static readonly OpCode Stelem_R8
Definition OpCodes.cs:321
static readonly OpCode Stind_Ref
Definition OpCodes.cs:165
static readonly OpCode Stfld
Definition OpCodes.cs:249
static readonly OpCode Newarr
Definition OpCodes.cs:281
static readonly OpCode Ldarg
Definition OpCodes.cs:419
static readonly OpCode Ldelem_I1
Definition OpCodes.cs:287
static readonly OpCode Conv_I8
Definition OpCodes.cs:215
static readonly OpCode Ldelem_R8
Definition OpCodes.cs:305
static readonly OpCode Ldelem_I8
Definition OpCodes.cs:299
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
virtual bool IsGenericParameter
Definition Type.cs:85
bool IsArray
Definition Type.cs:71
virtual MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberInfo member)
Definition Type.cs:649
virtual int GetArrayRank()
Definition Type.cs:490
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
ConstructorInfo? GetConstructor(Type[] types)
Definition Type.cs:542
virtual bool IsGenericType
Definition Type.cs:111
virtual bool IsSZArray
Definition Type.cs:116
override? Type DeclaringType
Definition Type.cs:55
bool IsVisible
Definition Type.cs:364
static readonly Type[] EmptyTypes
Definition Type.cs:19
TypeCode
Definition TypeCode.cs:4