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

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

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

Definition at line 765 of file IntPtr.cs.

766 {
767 if (typeof(TOther) == typeof(byte))
768 {
769 result = (byte)(object)value;
770 return true;
771 }
772 if (typeof(TOther) == typeof(char))
773 {
774 result = (char)(object)value;
775 return true;
776 }
777 if (typeof(TOther) == typeof(decimal))
778 {
779 decimal num = (decimal)(object)value;
780 if (num < (decimal)(long)MinValue || num > (decimal)(long)MaxValue)
781 {
782 result = 0;
783 return false;
784 }
785 result = (nint)(long)num;
786 return true;
787 }
788 if (typeof(TOther) == typeof(double))
789 {
790 double num2 = (double)(object)value;
791 if (num2 < (double)(nint)MinValue || num2 > (double)(nint)MaxValue)
792 {
793 result = 0;
794 return false;
795 }
796 result = (nint)num2;
797 return true;
798 }
799 if (typeof(TOther) == typeof(short))
800 {
801 result = (short)(object)value;
802 return true;
803 }
804 if (typeof(TOther) == typeof(int))
805 {
806 result = (int)(object)value;
807 return true;
808 }
809 if (typeof(TOther) == typeof(long))
810 {
811 long num3 = (long)(object)value;
812 if (num3 < (nint)MinValue || num3 > (nint)MaxValue)
813 {
814 result = 0;
815 return false;
816 }
817 result = (nint)num3;
818 return true;
819 }
820 if (typeof(TOther) == typeof(IntPtr))
821 {
822 result = (IntPtr)(object)value;
823 return true;
824 }
825 if (typeof(TOther) == typeof(sbyte))
826 {
827 result = (sbyte)(object)value;
828 return true;
829 }
830 if (typeof(TOther) == typeof(float))
831 {
832 float num4 = (float)(object)value;
833 if (num4 < (float)(nint)MinValue || num4 > (float)(nint)MaxValue)
834 {
835 result = 0;
836 return false;
837 }
838 result = (nint)num4;
839 return true;
840 }
841 if (typeof(TOther) == typeof(ushort))
842 {
843 result = (ushort)(object)value;
844 return true;
845 }
846 if (typeof(TOther) == typeof(uint))
847 {
848 uint num5 = (uint)(object)value;
849 if (num5 > (nint)MaxValue)
850 {
851 result = 0;
852 return false;
853 }
854 result = (nint)num5;
855 return true;
856 }
857 if (typeof(TOther) == typeof(ulong))
858 {
859 ulong num6 = (ulong)(object)value;
860 if (num6 > (nuint)(nint)MaxValue)
861 {
862 result = 0;
863 return false;
864 }
865 result = (nint)num6;
866 return true;
867 }
868 if (typeof(TOther) == typeof(UIntPtr))
869 {
870 UIntPtr uIntPtr = (UIntPtr)(object)value;
871 if ((nuint)uIntPtr > (nuint)(nint)MaxValue)
872 {
873 result = 0;
874 return false;
875 }
876 result = (nint)(nuint)uIntPtr;
877 return true;
878 }
879 ThrowHelper.ThrowNotSupportedException();
880 result = 0;
881 return false;
882 }
static IntPtr MaxValue
Definition IntPtr.cs:30
unsafe IntPtr(int value)
Definition IntPtr.cs:69
static IntPtr MinValue
Definition IntPtr.cs:39

References System.IntPtr.IntPtr(), System.Runtime.Serialization.Dictionary, System.IntPtr.MaxValue, System.IntPtr.MinValue, System.ThrowHelper.ThrowNotSupportedException(), and System.value.