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