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

◆ CreateSaturating< TOther >()

static short INumber< short >. System.Int16.CreateSaturating< TOther > ( TOther value)
inlinestatic

Definition at line 508 of file Int16.cs.

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

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