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

◆ CreateSaturating< TOther >()

static byte INumber< byte >. System.Byte.CreateSaturating< TOther > ( TOther value)
inlinestatic

Definition at line 501 of file Byte.cs.

502 {
503 if (typeof(TOther) == typeof(byte))
504 {
505 return (byte)(object)value;
506 }
507 if (typeof(TOther) == typeof(char))
508 {
509 char c = (char)(object)value;
510 if (c <= 'ΓΏ')
511 {
512 return (byte)c;
513 }
514 return byte.MaxValue;
515 }
516 if (typeof(TOther) == typeof(decimal))
517 {
518 decimal num = (decimal)(object)value;
519 if (!(num > 255m))
520 {
521 if (!(num < 0m))
522 {
523 return (byte)num;
524 }
525 return 0;
526 }
527 return byte.MaxValue;
528 }
529 if (typeof(TOther) == typeof(double))
530 {
531 double num2 = (double)(object)value;
532 if (!(num2 > 255.0))
533 {
534 if (!(num2 < 0.0))
535 {
536 return (byte)num2;
537 }
538 return 0;
539 }
540 return byte.MaxValue;
541 }
542 if (typeof(TOther) == typeof(short))
543 {
544 short num3 = (short)(object)value;
545 if (num3 <= 255)
546 {
547 if (num3 >= 0)
548 {
549 return (byte)num3;
550 }
551 return 0;
552 }
553 return byte.MaxValue;
554 }
555 if (typeof(TOther) == typeof(int))
556 {
557 int num4 = (int)(object)value;
558 if (num4 <= 255)
559 {
560 if (num4 >= 0)
561 {
562 return (byte)num4;
563 }
564 return 0;
565 }
566 return byte.MaxValue;
567 }
568 if (typeof(TOther) == typeof(long))
569 {
570 long num5 = (long)(object)value;
571 if (num5 <= 255)
572 {
573 if (num5 >= 0)
574 {
575 return (byte)num5;
576 }
577 return 0;
578 }
579 return byte.MaxValue;
580 }
581 if (typeof(TOther) == typeof(IntPtr))
582 {
583 IntPtr intPtr = (IntPtr)(object)value;
584 if ((nint)intPtr <= 255)
585 {
586 if ((nint)intPtr >= 0)
587 {
588 return (byte)(nint)intPtr;
589 }
590 return 0;
591 }
592 return byte.MaxValue;
593 }
594 if (typeof(TOther) == typeof(sbyte))
595 {
596 sbyte b = (sbyte)(object)value;
597 if (b >= 0)
598 {
599 return (byte)b;
600 }
601 return 0;
602 }
603 if (typeof(TOther) == typeof(float))
604 {
605 float num6 = (float)(object)value;
606 if (!(num6 > 255f))
607 {
608 if (!(num6 < 0f))
609 {
610 return (byte)num6;
611 }
612 return 0;
613 }
614 return byte.MaxValue;
615 }
616 if (typeof(TOther) == typeof(ushort))
617 {
618 ushort num7 = (ushort)(object)value;
619 if (num7 <= 255)
620 {
621 return (byte)num7;
622 }
623 return byte.MaxValue;
624 }
625 if (typeof(TOther) == typeof(uint))
626 {
627 uint num8 = (uint)(object)value;
628 if (num8 <= 255)
629 {
630 return (byte)num8;
631 }
632 return byte.MaxValue;
633 }
634 if (typeof(TOther) == typeof(ulong))
635 {
636 ulong num9 = (ulong)(object)value;
637 if (num9 <= 255)
638 {
639 return (byte)num9;
640 }
641 return byte.MaxValue;
642 }
643 if (typeof(TOther) == typeof(UIntPtr))
644 {
645 UIntPtr uIntPtr = (UIntPtr)(object)value;
646 if ((nuint)uIntPtr <= 255)
647 {
648 return (byte)(nuint)uIntPtr;
649 }
650 return byte.MaxValue;
651 }
652 ThrowHelper.ThrowNotSupportedException();
653 return 0;
654 }

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