Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryCreate< TOther >() [1/2]

static bool INumber< int >. System.Int32.TryCreate< TOther > ( TOther value,
out int result )
inlinestatic

Definition at line 728 of file Int32.cs.

729 {
730 if (typeof(TOther) == typeof(byte))
731 {
732 result = (byte)(object)value;
733 return true;
734 }
735 if (typeof(TOther) == typeof(char))
736 {
737 result = (char)(object)value;
738 return true;
739 }
740 if (typeof(TOther) == typeof(decimal))
741 {
742 decimal num = (decimal)(object)value;
743 if (num < -2147483648m || num > 2147483647m)
744 {
745 result = 0;
746 return false;
747 }
748 result = (int)num;
749 return true;
750 }
751 if (typeof(TOther) == typeof(double))
752 {
753 double num2 = (double)(object)value;
754 if (num2 < -2147483648.0 || num2 > 2147483647.0)
755 {
756 result = 0;
757 return false;
758 }
759 result = (int)num2;
760 return true;
761 }
762 if (typeof(TOther) == typeof(short))
763 {
764 result = (short)(object)value;
765 return true;
766 }
767 if (typeof(TOther) == typeof(int))
768 {
769 result = (int)(object)value;
770 return true;
771 }
772 if (typeof(TOther) == typeof(long))
773 {
774 long num3 = (long)(object)value;
775 if (num3 < int.MinValue || num3 > int.MaxValue)
776 {
777 result = 0;
778 return false;
779 }
780 result = (int)num3;
781 return true;
782 }
783 if (typeof(TOther) == typeof(IntPtr))
784 {
785 IntPtr intPtr = (IntPtr)(object)value;
786 if ((nint)intPtr < int.MinValue || (nint)intPtr > int.MaxValue)
787 {
788 result = 0;
789 return false;
790 }
791 result = (int)(nint)intPtr;
792 return true;
793 }
794 if (typeof(TOther) == typeof(sbyte))
795 {
796 result = (sbyte)(object)value;
797 return true;
798 }
799 if (typeof(TOther) == typeof(float))
800 {
801 float num4 = (float)(object)value;
802 if (num4 < -2.1474836E+09f || num4 > 2.1474836E+09f)
803 {
804 result = 0;
805 return false;
806 }
807 result = (int)num4;
808 return true;
809 }
810 if (typeof(TOther) == typeof(ushort))
811 {
812 result = (ushort)(object)value;
813 return true;
814 }
815 if (typeof(TOther) == typeof(uint))
816 {
817 uint num5 = (uint)(object)value;
818 if (num5 > int.MaxValue)
819 {
820 result = 0;
821 return false;
822 }
823 result = (int)num5;
824 return true;
825 }
826 if (typeof(TOther) == typeof(ulong))
827 {
828 ulong num6 = (ulong)(object)value;
829 if (num6 > int.MaxValue)
830 {
831 result = 0;
832 return false;
833 }
834 result = (int)num6;
835 return true;
836 }
837 if (typeof(TOther) == typeof(UIntPtr))
838 {
839 UIntPtr uIntPtr = (UIntPtr)(object)value;
840 if ((nuint)uIntPtr > int.MaxValue)
841 {
842 result = 0;
843 return false;
844 }
845 result = (int)(nuint)uIntPtr;
846 return true;
847 }
848 ThrowHelper.ThrowNotSupportedException();
849 result = 0;
850 return false;
851 }
const int MaxValue
Definition Int32.cs:15

References System.E, System.Int32.MaxValue, System.UIntPtr.MaxValue, System.ThrowHelper.ThrowNotSupportedException(), and System.value.