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

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

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

Definition at line 763 of file UIntPtr.cs.

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

References System.UIntPtr.UIntPtr(), System.Runtime.Serialization.Dictionary, System.UIntPtr.MaxValue, System.UIntPtr.Size, System.ThrowHelper.ThrowNotSupportedException(), and System.value.