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

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

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

Definition at line 730 of file UInt32.cs.

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

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