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

◆ CreateSaturating< TOther >()

static int INumber< int >. System.Int32.CreateSaturating< TOther > ( TOther value)
inlinestatic

Definition at line 504 of file Int32.cs.

505 {
506 if (typeof(TOther) == typeof(byte))
507 {
508 return (byte)(object)value;
509 }
510 if (typeof(TOther) == typeof(char))
511 {
512 return (char)(object)value;
513 }
514 if (typeof(TOther) == typeof(decimal))
515 {
516 decimal num = (decimal)(object)value;
517 if (!(num > 2147483647m))
518 {
519 if (!(num < -2147483648m))
520 {
521 return (int)num;
522 }
523 return int.MinValue;
524 }
525 return int.MaxValue;
526 }
527 if (typeof(TOther) == typeof(double))
528 {
529 double num2 = (double)(object)value;
530 if (!(num2 > 2147483647.0))
531 {
532 if (!(num2 < -2147483648.0))
533 {
534 return (int)num2;
535 }
536 return int.MinValue;
537 }
538 return int.MaxValue;
539 }
540 if (typeof(TOther) == typeof(short))
541 {
542 return (short)(object)value;
543 }
544 if (typeof(TOther) == typeof(int))
545 {
546 return (int)(object)value;
547 }
548 if (typeof(TOther) == typeof(long))
549 {
550 long num3 = (long)(object)value;
551 if (num3 <= int.MaxValue)
552 {
553 if (num3 >= int.MinValue)
554 {
555 return (int)num3;
556 }
557 return int.MinValue;
558 }
559 return int.MaxValue;
560 }
561 if (typeof(TOther) == typeof(IntPtr))
562 {
563 IntPtr intPtr = (IntPtr)(object)value;
564 if ((nint)intPtr <= int.MaxValue)
565 {
566 if ((nint)intPtr >= int.MinValue)
567 {
568 return (int)(nint)intPtr;
569 }
570 return int.MinValue;
571 }
572 return int.MaxValue;
573 }
574 if (typeof(TOther) == typeof(sbyte))
575 {
576 return (sbyte)(object)value;
577 }
578 if (typeof(TOther) == typeof(float))
579 {
580 float num4 = (float)(object)value;
581 if (!(num4 > 2.1474836E+09f))
582 {
583 if (!(num4 < -2.1474836E+09f))
584 {
585 return (int)num4;
586 }
587 return int.MinValue;
588 }
589 return int.MaxValue;
590 }
591 if (typeof(TOther) == typeof(ushort))
592 {
593 return (ushort)(object)value;
594 }
595 if (typeof(TOther) == typeof(uint))
596 {
597 uint num5 = (uint)(object)value;
598 if (num5 <= int.MaxValue)
599 {
600 return (int)num5;
601 }
602 return int.MaxValue;
603 }
604 if (typeof(TOther) == typeof(ulong))
605 {
606 ulong num6 = (ulong)(object)value;
607 if (num6 <= int.MaxValue)
608 {
609 return (int)num6;
610 }
611 return int.MaxValue;
612 }
613 if (typeof(TOther) == typeof(UIntPtr))
614 {
615 UIntPtr uIntPtr = (UIntPtr)(object)value;
616 if ((nuint)uIntPtr <= int.MaxValue)
617 {
618 return (int)(nuint)uIntPtr;
619 }
620 return int.MaxValue;
621 }
622 ThrowHelper.ThrowNotSupportedException();
623 return 0;
624 }
const int MinValue
Definition Int32.cs:17
const int MaxValue
Definition Int32.cs:15

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