Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Int16.cs
Go to the documentation of this file.
6
7namespace System;
8
10[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
11public readonly struct Int16 : IComparable, IConvertible, ISpanFormattable, IFormattable, IComparable<short>, IEquatable<short>, IBinaryInteger<short>, IBinaryNumber<short>, IBitwiseOperators<short, short, short>, INumber<short>, IAdditionOperators<short, short, short>, IAdditiveIdentity<short, short>, IComparisonOperators<short, short>, IEqualityOperators<short, short>, IDecrementOperators<short>, IDivisionOperators<short, short, short>, IIncrementOperators<short>, IModulusOperators<short, short, short>, IMultiplicativeIdentity<short, short>, IMultiplyOperators<short, short, short>, ISpanParseable<short>, IParseable<short>, ISubtractionOperators<short, short, short>, IUnaryNegationOperators<short, short>, IUnaryPlusOperators<short, short>, IShiftOperators<short, short>, IMinMaxValue<short>, ISignedNumber<short>
12{
13 private readonly short m_value;
14
15 public const short MaxValue = 32767;
16
17 public const short MinValue = -32768;
18
19 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
21
22 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
23 static short IMinMaxValue<short>.MinValue => short.MinValue;
24
25 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
26 static short IMinMaxValue<short>.MaxValue => short.MaxValue;
27
28 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
30
31 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
32 static short INumber<short>.One => 1;
33
34 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
35 static short INumber<short>.Zero => 0;
36
37 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
39
40 public int CompareTo(object? value)
41 {
42 if (value == null)
43 {
44 return 1;
45 }
46 if (value is short)
47 {
48 return this - (short)value;
49 }
51 }
52
53 public int CompareTo(short value)
54 {
55 return this - value;
56 }
57
58 public override bool Equals([NotNullWhen(true)] object? obj)
59 {
60 if (!(obj is short))
61 {
62 return false;
63 }
64 return this == (short)obj;
65 }
66
67 [NonVersionable]
68 public bool Equals(short obj)
69 {
70 return this == obj;
71 }
72
73 public override int GetHashCode()
74 {
75 return this;
76 }
77
78 public override string ToString()
79 {
80 return Number.Int32ToDecStr(this);
81 }
82
83 public string ToString(IFormatProvider? provider)
84 {
85 return Number.FormatInt32(this, 0, null, provider);
86 }
87
88 public string ToString(string? format)
89 {
90 return ToString(format, null);
91 }
92
93 public string ToString(string? format, IFormatProvider? provider)
94 {
95 return Number.FormatInt32(this, 65535, format, provider);
96 }
97
98 public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default(ReadOnlySpan<char>), IFormatProvider? provider = null)
99 {
100 return Number.TryFormatInt32(this, 65535, format, provider, destination, out charsWritten);
101 }
102
103 public static short Parse(string s)
104 {
105 if (s == null)
106 {
108 }
110 }
111
112 public static short Parse(string s, NumberStyles style)
113 {
115 if (s == null)
116 {
118 }
120 }
121
122 public static short Parse(string s, IFormatProvider? provider)
123 {
124 if (s == null)
125 {
127 }
129 }
130
131 public static short Parse(string s, NumberStyles style, IFormatProvider? provider)
132 {
134 if (s == null)
135 {
137 }
138 return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider));
139 }
140
141 public static short Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
142 {
144 return Parse(s, style, NumberFormatInfo.GetInstance(provider));
145 }
146
148 {
149 int result;
150 Number.ParsingStatus parsingStatus = Number.TryParseInt32(s, style, info, out result);
151 if (parsingStatus != 0)
152 {
153 Number.ThrowOverflowOrFormatException(parsingStatus, TypeCode.Int16);
154 }
155 if ((uint)(result - -32768 - ((int)(style & NumberStyles.AllowHexSpecifier) << 6)) > 65535u)
156 {
158 }
159 return (short)result;
160 }
161
162 public static bool TryParse([NotNullWhen(true)] string? s, out short result)
163 {
164 if (s == null)
165 {
166 result = 0;
167 return false;
168 }
170 }
171
172 public static bool TryParse(ReadOnlySpan<char> s, out short result)
173 {
174 return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
175 }
176
177 public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out short result)
178 {
180 if (s == null)
181 {
182 result = 0;
183 return false;
184 }
185 return TryParse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider), out result);
186 }
187
188 public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out short result)
189 {
191 return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
192 }
193
194 private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info, out short result)
195 {
196 if (Number.TryParseInt32(s, style, info, out var result2) != 0 || (uint)(result2 - -32768 - ((int)(style & NumberStyles.AllowHexSpecifier) << 6)) > 65535u)
197 {
198 result = 0;
199 return false;
200 }
201 result = (short)result2;
202 return true;
203 }
204
206 {
207 return TypeCode.Int16;
208 }
209
211 {
212 return Convert.ToBoolean(this);
213 }
214
216 {
217 return Convert.ToChar(this);
218 }
219
221 {
222 return Convert.ToSByte(this);
223 }
224
226 {
227 return Convert.ToByte(this);
228 }
229
231 {
232 return this;
233 }
234
236 {
237 return Convert.ToUInt16(this);
238 }
239
241 {
242 return Convert.ToInt32(this);
243 }
244
246 {
247 return Convert.ToUInt32(this);
248 }
249
251 {
252 return Convert.ToInt64(this);
253 }
254
256 {
257 return Convert.ToUInt64(this);
258 }
259
261 {
262 return Convert.ToSingle(this);
263 }
264
266 {
267 return Convert.ToDouble(this);
268 }
269
271 {
272 return Convert.ToDecimal(this);
273 }
274
276 {
277 throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int16", "DateTime"));
278 }
279
281 {
282 return Convert.DefaultToType(this, type, provider);
283 }
284
285 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
286 static short IAdditionOperators<short, short, short>.operator +(short left, short right)
287 {
288 return (short)(left + right);
289 }
290
291 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
293 {
294 return (short)(BitOperations.LeadingZeroCount((ushort)value) - 16);
295 }
296
297 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
299 {
300 return (short)BitOperations.PopCount((ushort)value);
301 }
302
303 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
304 static short IBinaryInteger<short>.RotateLeft(short value, int rotateAmount)
305 {
306 return (short)((value << (rotateAmount & 0xF)) | ((ushort)value >> ((16 - rotateAmount) & 0xF)));
307 }
308
309 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
310 static short IBinaryInteger<short>.RotateRight(short value, int rotateAmount)
311 {
312 return (short)(((ushort)value >> (rotateAmount & 0xF)) | (value << ((16 - rotateAmount) & 0xF)));
313 }
314
315 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
317 {
318 return (byte)(BitOperations.TrailingZeroCount(value << 16) - 16);
319 }
320
321 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
323 {
324 return BitOperations.IsPow2(value);
325 }
326
327 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
328 static short IBinaryNumber<short>.Log2(short value)
329 {
330 if (value < 0)
331 {
333 }
334 return (short)BitOperations.Log2((ushort)value);
335 }
336
337 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
338 static short IBitwiseOperators<short, short, short>.operator &(short left, short right)
339 {
340 return (short)(left & right);
341 }
342
343 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
344 static short IBitwiseOperators<short, short, short>.operator |(short left, short right)
345 {
346 return (short)(left | right);
347 }
348
349 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
350 static short IBitwiseOperators<short, short, short>.operator ^(short left, short right)
351 {
352 return (short)(left ^ right);
353 }
354
355 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
356 static short IBitwiseOperators<short, short, short>.operator ~(short value)
357 {
358 return (short)(~value);
359 }
360
361 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
362 static bool IComparisonOperators<short, short>.operator <(short left, short right)
363 {
364 return left < right;
365 }
366
367 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
368 static bool IComparisonOperators<short, short>.operator <=(short left, short right)
369 {
370 return left <= right;
371 }
372
373 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
374 static bool IComparisonOperators<short, short>.operator >(short left, short right)
375 {
376 return left > right;
377 }
378
379 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
380 static bool IComparisonOperators<short, short>.operator >=(short left, short right)
381 {
382 return left >= right;
383 }
384
385 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
386 static short IDecrementOperators<short>.operator --(short value)
387 {
388 return --value;
389 }
390
391 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
392 static short IDivisionOperators<short, short, short>.operator /(short left, short right)
393 {
394 return (short)(left / right);
395 }
396
397 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
398 static bool IEqualityOperators<short, short>.operator ==(short left, short right)
399 {
400 return left == right;
401 }
402
403 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
404 static bool IEqualityOperators<short, short>.operator !=(short left, short right)
405 {
406 return left != right;
407 }
408
409 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
410 static short IIncrementOperators<short>.operator ++(short value)
411 {
412 return ++value;
413 }
414
415 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
416 static short IModulusOperators<short, short, short>.operator %(short left, short right)
417 {
418 return (short)(left % right);
419 }
420
421 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
422 static short IMultiplyOperators<short, short, short>.operator *(short left, short right)
423 {
424 return (short)(left * right);
425 }
426
427 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
428 static short INumber<short>.Abs(short value)
429 {
430 return Math.Abs(value);
431 }
432
433 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
434 static short INumber<short>.Clamp(short value, short min, short max)
435 {
436 return Math.Clamp(value, min, max);
437 }
438
439 [MethodImpl(MethodImplOptions.AggressiveInlining)]
440 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
441 static short INumber<short>.Create<TOther>(TOther value)
442 {
443 if (typeof(TOther) == typeof(byte))
444 {
445 return (byte)(object)value;
446 }
447 checked
448 {
449 if (typeof(TOther) == typeof(char))
450 {
451 return (short)(char)(object)value;
452 }
453 if (typeof(TOther) == typeof(decimal))
454 {
455 return (short)(decimal)(object)value;
456 }
457 if (typeof(TOther) == typeof(double))
458 {
459 return (short)(double)(object)value;
460 }
461 if (typeof(TOther) == typeof(short))
462 {
463 return (short)(object)value;
464 }
465 if (typeof(TOther) == typeof(int))
466 {
467 return (short)(int)(object)value;
468 }
469 if (typeof(TOther) == typeof(long))
470 {
471 return (short)(long)(object)value;
472 }
473 if (typeof(TOther) == typeof(IntPtr))
474 {
475 return (short)(nint)(IntPtr)(object)value;
476 }
477 if (typeof(TOther) == typeof(sbyte))
478 {
479 return (sbyte)(object)value;
480 }
481 if (typeof(TOther) == typeof(float))
482 {
483 return (short)(float)(object)value;
484 }
485 if (typeof(TOther) == typeof(ushort))
486 {
487 return (short)(ushort)(object)value;
488 }
489 if (typeof(TOther) == typeof(uint))
490 {
491 return (short)(uint)(object)value;
492 }
493 if (typeof(TOther) == typeof(ulong))
494 {
495 return (short)(ulong)(object)value;
496 }
497 if (typeof(TOther) == typeof(UIntPtr))
498 {
499 return (short)(nuint)(UIntPtr)(object)value;
500 }
502 return 0;
503 }
504 }
505
506 [MethodImpl(MethodImplOptions.AggressiveInlining)]
507 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
508 static short INumber<short>.CreateSaturating<TOther>(TOther value)
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 }
646 return 0;
647 }
648
649 [MethodImpl(MethodImplOptions.AggressiveInlining)]
650 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
651 static short INumber<short>.CreateTruncating<TOther>(TOther value)
652 {
653 if (typeof(TOther) == typeof(byte))
654 {
655 return (byte)(object)value;
656 }
657 if (typeof(TOther) == typeof(char))
658 {
659 return (short)(char)(object)value;
660 }
661 if (typeof(TOther) == typeof(decimal))
662 {
663 return (short)(decimal)(object)value;
664 }
665 if (typeof(TOther) == typeof(double))
666 {
667 return (short)(double)(object)value;
668 }
669 if (typeof(TOther) == typeof(short))
670 {
671 return (short)(object)value;
672 }
673 if (typeof(TOther) == typeof(int))
674 {
675 return (short)(int)(object)value;
676 }
677 if (typeof(TOther) == typeof(long))
678 {
679 return (short)(long)(object)value;
680 }
681 if (typeof(TOther) == typeof(IntPtr))
682 {
683 return (short)(nint)(IntPtr)(object)value;
684 }
685 if (typeof(TOther) == typeof(sbyte))
686 {
687 return (sbyte)(object)value;
688 }
689 if (typeof(TOther) == typeof(float))
690 {
691 return (short)(float)(object)value;
692 }
693 if (typeof(TOther) == typeof(ushort))
694 {
695 return (short)(ushort)(object)value;
696 }
697 if (typeof(TOther) == typeof(uint))
698 {
699 return (short)(uint)(object)value;
700 }
701 if (typeof(TOther) == typeof(ulong))
702 {
703 return (short)(ulong)(object)value;
704 }
705 if (typeof(TOther) == typeof(UIntPtr))
706 {
707 return (short)(nuint)(UIntPtr)(object)value;
708 }
710 return 0;
711 }
712
713 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
714 static (short Quotient, short Remainder) INumber<short>.DivRem(short left, short right)
715 {
716 return Math.DivRem(left, right);
717 }
718
719 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
720 static short INumber<short>.Max(short x, short y)
721 {
722 return Math.Max(x, y);
723 }
724
725 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
726 static short INumber<short>.Min(short x, short y)
727 {
728 return Math.Min(x, y);
729 }
730
731 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
732 static short INumber<short>.Parse(string s, NumberStyles style, IFormatProvider provider)
733 {
734 return Parse(s, style, provider);
735 }
736
737 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
739 {
740 return Parse(s, style, provider);
741 }
742
743 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
744 static short INumber<short>.Sign(short value)
745 {
746 return (short)Math.Sign(value);
747 }
748
749 [MethodImpl(MethodImplOptions.AggressiveInlining)]
750 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
751 static bool INumber<short>.TryCreate<TOther>(TOther value, out short result)
752 {
753 if (typeof(TOther) == typeof(byte))
754 {
755 result = (byte)(object)value;
756 return true;
757 }
758 if (typeof(TOther) == typeof(char))
759 {
760 char c = (char)(object)value;
761 if (c > 'ç¿¿')
762 {
763 result = 0;
764 return false;
765 }
766 result = (short)c;
767 return true;
768 }
769 if (typeof(TOther) == typeof(decimal))
770 {
771 decimal num = (decimal)(object)value;
772 if (num < -32768m || num > 32767m)
773 {
774 result = 0;
775 return false;
776 }
777 result = (short)num;
778 return true;
779 }
780 if (typeof(TOther) == typeof(double))
781 {
782 double num2 = (double)(object)value;
783 if (num2 < -32768.0 || num2 > 32767.0)
784 {
785 result = 0;
786 return false;
787 }
788 result = (short)num2;
789 return true;
790 }
791 if (typeof(TOther) == typeof(short))
792 {
793 result = (short)(object)value;
794 return true;
795 }
796 if (typeof(TOther) == typeof(int))
797 {
798 int num3 = (int)(object)value;
799 if (num3 < -32768 || num3 > 32767)
800 {
801 result = 0;
802 return false;
803 }
804 result = (short)num3;
805 return true;
806 }
807 if (typeof(TOther) == typeof(long))
808 {
809 long num4 = (long)(object)value;
810 if (num4 < -32768 || num4 > 32767)
811 {
812 result = 0;
813 return false;
814 }
815 result = (short)num4;
816 return true;
817 }
818 if (typeof(TOther) == typeof(IntPtr))
819 {
820 IntPtr intPtr = (IntPtr)(object)value;
821 if ((nint)intPtr < -32768 || (nint)intPtr > 32767)
822 {
823 result = 0;
824 return false;
825 }
826 result = (short)(nint)intPtr;
827 return true;
828 }
829 if (typeof(TOther) == typeof(sbyte))
830 {
831 result = (sbyte)(object)value;
832 return true;
833 }
834 if (typeof(TOther) == typeof(float))
835 {
836 float num5 = (float)(object)value;
837 if (num5 < -32768f || num5 > 32767f)
838 {
839 result = 0;
840 return false;
841 }
842 result = (short)num5;
843 return true;
844 }
845 if (typeof(TOther) == typeof(ushort))
846 {
847 ushort num6 = (ushort)(object)value;
848 if (num6 > 32767)
849 {
850 result = 0;
851 return false;
852 }
853 result = (short)num6;
854 return true;
855 }
856 if (typeof(TOther) == typeof(uint))
857 {
858 uint num7 = (uint)(object)value;
859 if ((long)num7 > 32767L)
860 {
861 result = 0;
862 return false;
863 }
864 result = (short)num7;
865 return true;
866 }
867 if (typeof(TOther) == typeof(ulong))
868 {
869 ulong num8 = (ulong)(object)value;
870 if (num8 > 32767)
871 {
872 result = 0;
873 return false;
874 }
875 result = (short)num8;
876 return true;
877 }
878 if (typeof(TOther) == typeof(UIntPtr))
879 {
880 UIntPtr uIntPtr = (UIntPtr)(object)value;
881 if ((nuint)uIntPtr > 32767)
882 {
883 result = 0;
884 return false;
885 }
886 result = (short)(nuint)uIntPtr;
887 return true;
888 }
890 result = 0;
891 return false;
892 }
893
894 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
895 static bool INumber<short>.TryParse([NotNullWhen(true)] string s, NumberStyles style, IFormatProvider provider, out short result)
896 {
897 return TryParse(s, style, provider, out result);
898 }
899
900 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
901 static bool INumber<short>.TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out short result)
902 {
903 return TryParse(s, style, provider, out result);
904 }
905
906 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
907 static short IParseable<short>.Parse(string s, IFormatProvider provider)
908 {
909 return Parse(s, provider);
910 }
911
912 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
913 static bool IParseable<short>.TryParse([NotNullWhen(true)] string s, IFormatProvider provider, out short result)
914 {
915 return TryParse(s, NumberStyles.Integer, provider, out result);
916 }
917
918 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
919 static short IShiftOperators<short, short>.operator <<(short value, int shiftAmount)
920 {
921 return (short)(value << shiftAmount);
922 }
923
924 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
925 static short IShiftOperators<short, short>.operator >>(short value, int shiftAmount)
926 {
927 return (short)(value >> shiftAmount);
928 }
929
930 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
932 {
933 return Parse(s, NumberStyles.Integer, provider);
934 }
935
936 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
937 static bool ISpanParseable<short>.TryParse(ReadOnlySpan<char> s, IFormatProvider provider, out short result)
938 {
939 return TryParse(s, NumberStyles.Integer, provider, out result);
940 }
941
942 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
943 static short ISubtractionOperators<short, short, short>.operator -(short left, short right)
944 {
945 return (short)(left - right);
946 }
947
948 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
949 static short IUnaryNegationOperators<short, short>.operator -(short value)
950 {
951 return (short)(-value);
952 }
953
954 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
955 static short IUnaryPlusOperators<short, short>.operator +(short value)
956 {
957 return value;
958 }
959}
static decimal ToDecimal(object? value)
Definition Convert.cs:2101
static long ToInt64(object? value)
Definition Convert.cs:1623
static float ToSingle(object? value)
Definition Convert.cs:1881
static int ToInt32(object? value)
Definition Convert.cs:1320
static byte ToByte(object? value)
Definition Convert.cs:900
static uint ToUInt32(object? value)
Definition Convert.cs:1470
static ulong ToUInt64(object? value)
Definition Convert.cs:1738
static char ToChar(object? value)
Definition Convert.cs:618
static ushort ToUInt16(object? value)
Definition Convert.cs:1177
static sbyte ToSByte(object? value)
Definition Convert.cs:745
static double ToDouble(object? value)
Definition Convert.cs:1991
static bool ToBoolean([NotNullWhen(true)] object? value)
Definition Convert.cs:508
static object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
Definition Convert.cs:269
static void ValidateParseStyleInteger(NumberStyles style)
static NumberFormatInfo GetInstance(IFormatProvider? formatProvider)
static byte Clamp(byte value, byte min, byte max)
Definition Math.cs:435
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Abs(double value)
static int DivRem(int a, int b, out int result)
Definition Math.cs:329
static int Sign(decimal value)
Definition Math.cs:1202
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static void ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type=TypeCode.Empty)
Definition Number.cs:5918
static void ThrowOverflowException(TypeCode type)
Definition Number.cs:5924
static string FormatInt32(int value, int hexMask, string format, IFormatProvider provider)
Definition Number.cs:1882
static string Int32ToDecStr(int value)
Definition Number.cs:2246
static ParsingStatus TryParseInt32(ReadOnlySpan< char > value, NumberStyles styles, NumberFormatInfo info, out int result)
Definition Number.cs:4251
static bool TryFormatInt32(int value, int hexMask, ReadOnlySpan< char > format, IFormatProvider provider, Span< char > destination, out int charsWritten)
Definition Number.cs:1929
static int TrailingZeroCount(int value)
static bool IsPow2(int value)
static int PopCount(uint value)
static int Log2(uint value)
static int LeadingZeroCount(uint value)
static string Arg_MustBeInt16
Definition SR.cs:280
static string InvalidCast_FromTo
Definition SR.cs:1392
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
static void ThrowNotSupportedException(ExceptionResource resource)
static void ThrowValueArgumentOutOfRange_NeedNonNegNumException()
static void ThrowArgumentNullException(string name)
static TResult AdditiveIdentity
static TSelf RotateRight(TSelf value, int rotateAmount)
static TSelf LeadingZeroCount(TSelf value)
static TSelf PopCount(TSelf value)
static TSelf TrailingZeroCount(TSelf value)
static TSelf RotateLeft(TSelf value, int rotateAmount)
static bool IsPow2(TSelf value)
static TSelf Log2(TSelf value)
short ToInt16(IFormatProvider? provider)
char ToChar(IFormatProvider? provider)
byte ToByte(IFormatProvider? provider)
decimal ToDecimal(IFormatProvider? provider)
object ToType(Type conversionType, IFormatProvider? provider)
uint ToUInt32(IFormatProvider? provider)
DateTime ToDateTime(IFormatProvider? provider)
int ToInt32(IFormatProvider? provider)
long ToInt64(IFormatProvider? provider)
ushort ToUInt16(IFormatProvider? provider)
double ToDouble(IFormatProvider? provider)
float ToSingle(IFormatProvider? provider)
sbyte ToSByte(IFormatProvider? provider)
ulong ToUInt64(IFormatProvider? provider)
bool ToBoolean(IFormatProvider? provider)
static TSelf MinValue
static TSelf MaxValue
static TSelf Max(TSelf x, TSelf y)
static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out TSelf result)
static TSelf Parse(string s, NumberStyles style, IFormatProvider? provider)
static TSelf Sign(TSelf value)
static TSelf Min(TSelf x, TSelf y)
static TSelf One
Definition INumber.cs:10
static TSelf Zero
Definition INumber.cs:12
static TSelf Abs(TSelf value)
static TSelf Clamp(TSelf value, TSelf min, TSelf max)
static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out TSelf result)
static TSelf Parse(string s, IFormatProvider? provider)
static TSelf NegativeOne
static bool TryParse(ReadOnlySpan< char > s, IFormatProvider? provider, out TSelf result)
static TSelf Parse(ReadOnlySpan< char > s, IFormatProvider? provider)
TypeCode
Definition TypeCode.cs:4
static short Parse(ReadOnlySpan< char > s, NumberStyles style, NumberFormatInfo info)
Definition Int16.cs:147
static short Quotient
Definition Int16.cs:714
const short MinValue
Definition Int16.cs:17
static bool TryParse(ReadOnlySpan< char > s, NumberStyles style, IFormatProvider? provider, out short result)
Definition Int16.cs:188
static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out short result)
Definition Int16.cs:177
static bool TryParse(ReadOnlySpan< char > s, out short result)
Definition Int16.cs:172
int CompareTo(short value)
Definition Int16.cs:53
readonly short m_value
Definition Int16.cs:13
override int GetHashCode()
Definition Int16.cs:73
int CompareTo(object? value)
Definition Int16.cs:40
bool Equals(short obj)
Definition Int16.cs:68
static bool TryParse(ReadOnlySpan< char > s, NumberStyles style, NumberFormatInfo info, out short result)
Definition Int16.cs:194
static short Parse(string s, NumberStyles style, IFormatProvider? provider)
Definition Int16.cs:131
string ToString(string? format, IFormatProvider? provider)
Definition Int16.cs:93
static short Parse(string s, NumberStyles style)
Definition Int16.cs:112
static bool TryParse([NotNullWhen(true)] string? s, out short result)
Definition Int16.cs:162
override string ToString()
Definition Int16.cs:78
static short Parse(string s, IFormatProvider? provider)
Definition Int16.cs:122
static short short Remainder INumber< short >. DivRem(short left, short right)
Definition Int16.cs:714
static short Parse(ReadOnlySpan< char > s, NumberStyles style=NumberStyles.Integer, IFormatProvider? provider=null)
Definition Int16.cs:141
override bool Equals([NotNullWhen(true)] object? obj)
Definition Int16.cs:58
string ToString(string? format)
Definition Int16.cs:88
bool TryFormat(Span< char > destination, out int charsWritten, ReadOnlySpan< char > format=default(ReadOnlySpan< char >), IFormatProvider? provider=null)
Definition Int16.cs:98
string ToString(IFormatProvider? provider)
Definition Int16.cs:83
static short Parse(string s)
Definition Int16.cs:103
const short MaxValue
Definition Int16.cs:15
TypeCode GetTypeCode()
Definition Int16.cs:205
static IntPtr MinValue
Definition IntPtr.cs:39
static UIntPtr MaxValue
Definition UIntPtr.cs:31