Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UInt16.cs
Go to the documentation of this file.
6
7namespace System;
8
10[CLSCompliant(false)]
11[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
12public readonly struct UInt16 : IComparable, IConvertible, ISpanFormattable, IFormattable, IComparable<ushort>, IEquatable<ushort>, IBinaryInteger<ushort>, IBinaryNumber<ushort>, IBitwiseOperators<ushort, ushort, ushort>, INumber<ushort>, IAdditionOperators<ushort, ushort, ushort>, IAdditiveIdentity<ushort, ushort>, IComparisonOperators<ushort, ushort>, IEqualityOperators<ushort, ushort>, IDecrementOperators<ushort>, IDivisionOperators<ushort, ushort, ushort>, IIncrementOperators<ushort>, IModulusOperators<ushort, ushort, ushort>, IMultiplicativeIdentity<ushort, ushort>, IMultiplyOperators<ushort, ushort, ushort>, ISpanParseable<ushort>, IParseable<ushort>, ISubtractionOperators<ushort, ushort, ushort>, IUnaryNegationOperators<ushort, ushort>, IUnaryPlusOperators<ushort, ushort>, IShiftOperators<ushort, ushort>, IMinMaxValue<ushort>, IUnsignedNumber<ushort>
13{
14 private readonly ushort m_value;
15
16 public const ushort MaxValue = 65535;
17
18 public const ushort MinValue = 0;
19
20 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
22
23 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
24 static ushort IMinMaxValue<ushort>.MinValue => 0;
25
26 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
27 static ushort IMinMaxValue<ushort>.MaxValue => ushort.MaxValue;
28
29 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
31
32 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
33 static ushort INumber<ushort>.One => 1;
34
35 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
36 static ushort INumber<ushort>.Zero => 0;
37
38 public int CompareTo(object? value)
39 {
40 if (value == null)
41 {
42 return 1;
43 }
44 if (value is ushort)
45 {
46 return this - (ushort)value;
47 }
49 }
50
51 public int CompareTo(ushort value)
52 {
53 return this - value;
54 }
55
56 public override bool Equals([NotNullWhen(true)] object? obj)
57 {
58 if (!(obj is ushort))
59 {
60 return false;
61 }
62 return this == (ushort)obj;
63 }
64
65 [NonVersionable]
66 public bool Equals(ushort obj)
67 {
68 return this == obj;
69 }
70
71 public override int GetHashCode()
72 {
73 return this;
74 }
75
76 public override string ToString()
77 {
78 return Number.UInt32ToDecStr(this);
79 }
80
81 public string ToString(IFormatProvider? provider)
82 {
83 return Number.UInt32ToDecStr(this);
84 }
85
86 public string ToString(string? format)
87 {
88 return Number.FormatUInt32(this, format, null);
89 }
90
91 public string ToString(string? format, IFormatProvider? provider)
92 {
93 return Number.FormatUInt32(this, format, provider);
94 }
95
96 public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default(ReadOnlySpan<char>), IFormatProvider? provider = null)
97 {
98 return Number.TryFormatUInt32(this, format, provider, destination, out charsWritten);
99 }
100
101 public static ushort Parse(string s)
102 {
103 if (s == null)
104 {
106 }
108 }
109
110 public static ushort Parse(string s, NumberStyles style)
111 {
113 if (s == null)
114 {
116 }
118 }
119
120 public static ushort Parse(string s, IFormatProvider? provider)
121 {
122 if (s == null)
123 {
125 }
127 }
128
129 public static ushort Parse(string s, NumberStyles style, IFormatProvider? provider)
130 {
132 if (s == null)
133 {
135 }
136 return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider));
137 }
138
139 public static ushort Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
140 {
142 return Parse(s, style, NumberFormatInfo.GetInstance(provider));
143 }
144
146 {
147 uint result;
148 Number.ParsingStatus parsingStatus = Number.TryParseUInt32(s, style, info, out result);
149 if (parsingStatus != 0)
150 {
151 Number.ThrowOverflowOrFormatException(parsingStatus, TypeCode.UInt16);
152 }
153 if (result > 65535)
154 {
156 }
157 return (ushort)result;
158 }
159
160 public static bool TryParse([NotNullWhen(true)] string? s, out ushort result)
161 {
162 if (s == null)
163 {
164 result = 0;
165 return false;
166 }
168 }
169
170 public static bool TryParse(ReadOnlySpan<char> s, out ushort result)
171 {
172 return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
173 }
174
175 public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out ushort result)
176 {
178 if (s == null)
179 {
180 result = 0;
181 return false;
182 }
183 return TryParse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider), out result);
184 }
185
186 public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out ushort result)
187 {
189 return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
190 }
191
192 private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info, out ushort result)
193 {
194 if (Number.TryParseUInt32(s, style, info, out var result2) != 0 || result2 > 65535)
195 {
196 result = 0;
197 return false;
198 }
199 result = (ushort)result2;
200 return true;
201 }
202
204 {
205 return TypeCode.UInt16;
206 }
207
209 {
210 return Convert.ToBoolean(this);
211 }
212
214 {
215 return Convert.ToChar(this);
216 }
217
219 {
220 return Convert.ToSByte(this);
221 }
222
224 {
225 return Convert.ToByte(this);
226 }
227
229 {
230 return Convert.ToInt16(this);
231 }
232
234 {
235 return this;
236 }
237
239 {
240 return Convert.ToInt32(this);
241 }
242
244 {
245 return Convert.ToUInt32(this);
246 }
247
249 {
250 return Convert.ToInt64(this);
251 }
252
254 {
255 return Convert.ToUInt64(this);
256 }
257
259 {
260 return Convert.ToSingle(this);
261 }
262
264 {
265 return Convert.ToDouble(this);
266 }
267
269 {
270 return Convert.ToDecimal(this);
271 }
272
274 {
275 throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt16", "DateTime"));
276 }
277
279 {
280 return Convert.DefaultToType(this, type, provider);
281 }
282
283 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
284 static ushort IAdditionOperators<ushort, ushort, ushort>.operator +(ushort left, ushort right)
285 {
286 return (ushort)(left + right);
287 }
288
289 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
291 {
292 return (ushort)(BitOperations.LeadingZeroCount(value) - 16);
293 }
294
295 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
297 {
298 return (ushort)BitOperations.PopCount(value);
299 }
300
301 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
302 static ushort IBinaryInteger<ushort>.RotateLeft(ushort value, int rotateAmount)
303 {
304 return (ushort)((value << (rotateAmount & 0xF)) | (value >> ((16 - rotateAmount) & 0xF)));
305 }
306
307 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
308 static ushort IBinaryInteger<ushort>.RotateRight(ushort value, int rotateAmount)
309 {
310 return (ushort)((value >> (rotateAmount & 0xF)) | (value << ((16 - rotateAmount) & 0xF)));
311 }
312
313 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
315 {
316 return (ushort)(BitOperations.TrailingZeroCount(value << 16) - 16);
317 }
318
319 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
321 {
322 return BitOperations.IsPow2((uint)value);
323 }
324
325 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
326 static ushort IBinaryNumber<ushort>.Log2(ushort value)
327 {
328 return (ushort)BitOperations.Log2(value);
329 }
330
331 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
332 static ushort IBitwiseOperators<ushort, ushort, ushort>.operator &(ushort left, ushort right)
333 {
334 return (ushort)(left & right);
335 }
336
337 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
338 static ushort IBitwiseOperators<ushort, ushort, ushort>.operator |(ushort left, ushort right)
339 {
340 return (ushort)(left | right);
341 }
342
343 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
344 static ushort IBitwiseOperators<ushort, ushort, ushort>.operator ^(ushort left, ushort right)
345 {
346 return (ushort)(left ^ right);
347 }
348
349 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
350 static ushort IBitwiseOperators<ushort, ushort, ushort>.operator ~(ushort value)
351 {
352 return (ushort)(~value);
353 }
354
355 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
356 static bool IComparisonOperators<ushort, ushort>.operator <(ushort left, ushort right)
357 {
358 return left < right;
359 }
360
361 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
362 static bool IComparisonOperators<ushort, ushort>.operator <=(ushort left, ushort 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<ushort, ushort>.operator >(ushort left, ushort 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<ushort, ushort>.operator >=(ushort left, ushort 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 ushort IDecrementOperators<ushort>.operator --(ushort value)
381 {
382 return --value;
383 }
384
385 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
386 static ushort IDivisionOperators<ushort, ushort, ushort>.operator /(ushort left, ushort right)
387 {
388 return (ushort)(left / right);
389 }
390
391 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
392 static bool IEqualityOperators<ushort, ushort>.operator ==(ushort left, ushort right)
393 {
394 return left == right;
395 }
396
397 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
398 static bool IEqualityOperators<ushort, ushort>.operator !=(ushort left, ushort 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 ushort IIncrementOperators<ushort>.operator ++(ushort value)
405 {
406 return ++value;
407 }
408
409 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
410 static ushort IModulusOperators<ushort, ushort, ushort>.operator %(ushort left, ushort right)
411 {
412 return (ushort)(left % right);
413 }
414
415 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
416 static ushort IMultiplyOperators<ushort, ushort, ushort>.operator *(ushort left, ushort right)
417 {
418 return (ushort)(left * right);
419 }
420
421 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
422 static ushort INumber<ushort>.Abs(ushort value)
423 {
424 return value;
425 }
426
427 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
428 static ushort INumber<ushort>.Clamp(ushort value, ushort min, ushort max)
429 {
430 return Math.Clamp(value, min, max);
431 }
432
433 [MethodImpl(MethodImplOptions.AggressiveInlining)]
434 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
435 static ushort INumber<ushort>.Create<TOther>(TOther value)
436 {
437 if (typeof(TOther) == typeof(byte))
438 {
439 return (byte)(object)value;
440 }
441 if (typeof(TOther) == typeof(char))
442 {
443 return (char)(object)value;
444 }
445 if (typeof(TOther) == typeof(decimal))
446 {
447 return (ushort)(decimal)(object)value;
448 }
449 checked
450 {
451 if (typeof(TOther) == typeof(double))
452 {
453 return (ushort)(double)(object)value;
454 }
455 if (typeof(TOther) == typeof(short))
456 {
457 return (ushort)(short)(object)value;
458 }
459 if (typeof(TOther) == typeof(int))
460 {
461 return (ushort)(int)(object)value;
462 }
463 if (typeof(TOther) == typeof(long))
464 {
465 return (ushort)(long)(object)value;
466 }
467 if (typeof(TOther) == typeof(IntPtr))
468 {
469 return (ushort)(nint)(IntPtr)(object)value;
470 }
471 if (typeof(TOther) == typeof(sbyte))
472 {
473 return (ushort)(sbyte)(object)value;
474 }
475 if (typeof(TOther) == typeof(float))
476 {
477 return (ushort)(float)(object)value;
478 }
479 if (typeof(TOther) == typeof(ushort))
480 {
481 return (ushort)(object)value;
482 }
483 if (typeof(TOther) == typeof(uint))
484 {
485 return (ushort)(uint)(object)value;
486 }
487 if (typeof(TOther) == typeof(ulong))
488 {
489 return (ushort)(ulong)(object)value;
490 }
491 if (typeof(TOther) == typeof(UIntPtr))
492 {
493 return (ushort)(nuint)(UIntPtr)(object)value;
494 }
496 return 0;
497 }
498 }
499
500 [MethodImpl(MethodImplOptions.AggressiveInlining)]
501 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
502 static ushort INumber<ushort>.CreateSaturating<TOther>(TOther value)
503 {
504 if (typeof(TOther) == typeof(byte))
505 {
506 return (byte)(object)value;
507 }
508 if (typeof(TOther) == typeof(char))
509 {
510 return (char)(object)value;
511 }
512 if (typeof(TOther) == typeof(decimal))
513 {
514 decimal num = (decimal)(object)value;
515 if (!(num > 65535m))
516 {
517 if (!(num < 0m))
518 {
519 return (ushort)num;
520 }
521 return 0;
522 }
523 return ushort.MaxValue;
524 }
525 if (typeof(TOther) == typeof(double))
526 {
527 double num2 = (double)(object)value;
528 if (!(num2 > 65535.0))
529 {
530 if (!(num2 < 0.0))
531 {
532 return (ushort)num2;
533 }
534 return 0;
535 }
536 return ushort.MaxValue;
537 }
538 if (typeof(TOther) == typeof(short))
539 {
540 short num3 = (short)(object)value;
541 if (num3 >= 0)
542 {
543 return (ushort)num3;
544 }
545 return 0;
546 }
547 if (typeof(TOther) == typeof(int))
548 {
549 int num4 = (int)(object)value;
550 if (num4 <= 65535)
551 {
552 if (num4 >= 0)
553 {
554 return (ushort)num4;
555 }
556 return 0;
557 }
558 return ushort.MaxValue;
559 }
560 if (typeof(TOther) == typeof(long))
561 {
562 long num5 = (long)(object)value;
563 if (num5 <= 65535)
564 {
565 if (num5 >= 0)
566 {
567 return (ushort)num5;
568 }
569 return 0;
570 }
571 return ushort.MaxValue;
572 }
573 if (typeof(TOther) == typeof(IntPtr))
574 {
575 IntPtr intPtr = (IntPtr)(object)value;
576 if ((nint)intPtr <= 65535)
577 {
578 if ((nint)intPtr >= 0)
579 {
580 return (ushort)(nint)intPtr;
581 }
582 return 0;
583 }
584 return ushort.MaxValue;
585 }
586 if (typeof(TOther) == typeof(sbyte))
587 {
588 sbyte b = (sbyte)(object)value;
589 if (b >= 0)
590 {
591 return (ushort)b;
592 }
593 return 0;
594 }
595 if (typeof(TOther) == typeof(float))
596 {
597 float num6 = (float)(object)value;
598 if (!(num6 > 65535f))
599 {
600 if (!(num6 < 0f))
601 {
602 return (ushort)num6;
603 }
604 return 0;
605 }
606 return ushort.MaxValue;
607 }
608 if (typeof(TOther) == typeof(ushort))
609 {
610 return (ushort)(object)value;
611 }
612 if (typeof(TOther) == typeof(uint))
613 {
614 uint num7 = (uint)(object)value;
615 if (num7 <= 65535)
616 {
617 return (ushort)num7;
618 }
619 return ushort.MaxValue;
620 }
621 if (typeof(TOther) == typeof(ulong))
622 {
623 ulong num8 = (ulong)(object)value;
624 if (num8 <= 65535)
625 {
626 return (ushort)num8;
627 }
628 return ushort.MaxValue;
629 }
630 if (typeof(TOther) == typeof(UIntPtr))
631 {
632 UIntPtr uIntPtr = (UIntPtr)(object)value;
633 if ((nuint)uIntPtr <= 65535)
634 {
635 return (ushort)(nuint)uIntPtr;
636 }
637 return ushort.MaxValue;
638 }
640 return 0;
641 }
642
643 [MethodImpl(MethodImplOptions.AggressiveInlining)]
644 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
645 static ushort INumber<ushort>.CreateTruncating<TOther>(TOther value)
646 {
647 if (typeof(TOther) == typeof(byte))
648 {
649 return (byte)(object)value;
650 }
651 if (typeof(TOther) == typeof(char))
652 {
653 return (char)(object)value;
654 }
655 if (typeof(TOther) == typeof(decimal))
656 {
657 return (ushort)(decimal)(object)value;
658 }
659 if (typeof(TOther) == typeof(double))
660 {
661 return (ushort)(double)(object)value;
662 }
663 if (typeof(TOther) == typeof(short))
664 {
665 return (ushort)(short)(object)value;
666 }
667 if (typeof(TOther) == typeof(int))
668 {
669 return (ushort)(int)(object)value;
670 }
671 if (typeof(TOther) == typeof(long))
672 {
673 return (ushort)(long)(object)value;
674 }
675 if (typeof(TOther) == typeof(IntPtr))
676 {
677 return (ushort)(nint)(IntPtr)(object)value;
678 }
679 if (typeof(TOther) == typeof(sbyte))
680 {
681 return (ushort)(sbyte)(object)value;
682 }
683 if (typeof(TOther) == typeof(float))
684 {
685 return (ushort)(float)(object)value;
686 }
687 if (typeof(TOther) == typeof(ushort))
688 {
689 return (ushort)(object)value;
690 }
691 if (typeof(TOther) == typeof(uint))
692 {
693 return (ushort)(uint)(object)value;
694 }
695 if (typeof(TOther) == typeof(ulong))
696 {
697 return (ushort)(ulong)(object)value;
698 }
699 if (typeof(TOther) == typeof(UIntPtr))
700 {
701 return (ushort)(nuint)(UIntPtr)(object)value;
702 }
704 return 0;
705 }
706
707 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
708 static (ushort Quotient, ushort Remainder) INumber<ushort>.DivRem(ushort left, ushort right)
709 {
710 return Math.DivRem(left, right);
711 }
712
713 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
714 static ushort INumber<ushort>.Max(ushort x, ushort y)
715 {
716 return Math.Max(x, y);
717 }
718
719 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
720 static ushort INumber<ushort>.Min(ushort x, ushort y)
721 {
722 return Math.Min(x, y);
723 }
724
725 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
726 static ushort INumber<ushort>.Parse(string s, NumberStyles style, IFormatProvider provider)
727 {
728 return Parse(s, style, provider);
729 }
730
731 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
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")]
738 static ushort INumber<ushort>.Sign(ushort value)
739 {
740 return (ushort)((value != 0) ? 1u : 0u);
741 }
742
743 [MethodImpl(MethodImplOptions.AggressiveInlining)]
744 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
745 static bool INumber<ushort>.TryCreate<TOther>(TOther value, out ushort result)
746 {
747 if (typeof(TOther) == typeof(byte))
748 {
749 result = (byte)(object)value;
750 return true;
751 }
752 if (typeof(TOther) == typeof(char))
753 {
754 result = (char)(object)value;
755 return true;
756 }
757 if (typeof(TOther) == typeof(decimal))
758 {
759 decimal num = (decimal)(object)value;
760 if (num < 0m || num > 65535m)
761 {
762 result = 0;
763 return false;
764 }
765 result = (ushort)num;
766 return true;
767 }
768 if (typeof(TOther) == typeof(double))
769 {
770 double num2 = (double)(object)value;
771 if (num2 < 0.0 || num2 > 65535.0)
772 {
773 result = 0;
774 return false;
775 }
776 result = (ushort)num2;
777 return true;
778 }
779 if (typeof(TOther) == typeof(short))
780 {
781 short num3 = (short)(object)value;
782 if (num3 < 0)
783 {
784 result = 0;
785 return false;
786 }
787 result = (ushort)num3;
788 return true;
789 }
790 if (typeof(TOther) == typeof(int))
791 {
792 int num4 = (int)(object)value;
793 if (num4 < 0 || num4 > 65535)
794 {
795 result = 0;
796 return false;
797 }
798 result = (ushort)num4;
799 return true;
800 }
801 if (typeof(TOther) == typeof(long))
802 {
803 long num5 = (long)(object)value;
804 if (num5 < 0 || num5 > 65535)
805 {
806 result = 0;
807 return false;
808 }
809 result = (ushort)num5;
810 return true;
811 }
812 if (typeof(TOther) == typeof(IntPtr))
813 {
814 IntPtr intPtr = (IntPtr)(object)value;
815 if ((nint)intPtr < 0 || (nint)intPtr > 65535)
816 {
817 result = 0;
818 return false;
819 }
820 result = (ushort)(nint)intPtr;
821 return true;
822 }
823 if (typeof(TOther) == typeof(sbyte))
824 {
825 sbyte b = (sbyte)(object)value;
826 if (b < 0)
827 {
828 result = 0;
829 return false;
830 }
831 result = (ushort)b;
832 return true;
833 }
834 if (typeof(TOther) == typeof(float))
835 {
836 float num6 = (float)(object)value;
837 if (num6 < 0f || num6 > 65535f)
838 {
839 result = 0;
840 return false;
841 }
842 result = (ushort)num6;
843 return true;
844 }
845 if (typeof(TOther) == typeof(ushort))
846 {
847 result = (ushort)(object)value;
848 return true;
849 }
850 if (typeof(TOther) == typeof(uint))
851 {
852 uint num7 = (uint)(object)value;
853 if (num7 > 65535)
854 {
855 result = 0;
856 return false;
857 }
858 result = (ushort)num7;
859 return true;
860 }
861 if (typeof(TOther) == typeof(ulong))
862 {
863 ulong num8 = (ulong)(object)value;
864 if (num8 > 65535)
865 {
866 result = 0;
867 return false;
868 }
869 result = (ushort)num8;
870 return true;
871 }
872 if (typeof(TOther) == typeof(UIntPtr))
873 {
874 UIntPtr uIntPtr = (UIntPtr)(object)value;
875 if ((nuint)uIntPtr > 65535)
876 {
877 result = 0;
878 return false;
879 }
880 result = (ushort)(nuint)uIntPtr;
881 return true;
882 }
884 result = 0;
885 return false;
886 }
887
888 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
889 static bool INumber<ushort>.TryParse([NotNullWhen(true)] string s, NumberStyles style, IFormatProvider provider, out ushort result)
890 {
891 return TryParse(s, style, provider, out result);
892 }
893
894 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
895 static bool INumber<ushort>.TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out ushort 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 ushort IParseable<ushort>.Parse(string s, IFormatProvider provider)
902 {
903 return Parse(s, provider);
904 }
905
906 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
907 static bool IParseable<ushort>.TryParse([NotNullWhen(true)] string s, IFormatProvider provider, out ushort result)
908 {
909 return TryParse(s, NumberStyles.Integer, provider, out result);
910 }
911
912 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
913 static ushort IShiftOperators<ushort, ushort>.operator <<(ushort value, int shiftAmount)
914 {
915 return (ushort)(value << shiftAmount);
916 }
917
918 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
919 static ushort IShiftOperators<ushort, ushort>.operator >>(ushort value, int shiftAmount)
920 {
921 return (ushort)(value >> shiftAmount);
922 }
923
924 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
926 {
927 return Parse(s, NumberStyles.Integer, provider);
928 }
929
930 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
931 static bool ISpanParseable<ushort>.TryParse(ReadOnlySpan<char> s, IFormatProvider provider, out ushort result)
932 {
933 return TryParse(s, NumberStyles.Integer, provider, out result);
934 }
935
936 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
937 static ushort ISubtractionOperators<ushort, ushort, ushort>.operator -(ushort left, ushort right)
938 {
939 return (ushort)(left - right);
940 }
941
942 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
943 static ushort IUnaryNegationOperators<ushort, ushort>.operator -(ushort value)
944 {
945 return (ushort)(-value);
946 }
947
948 [RequiresPreviewFeatures("Generic Math is in preview.", Url = "https://aka.ms/dotnet-warnings/generic-math-preview")]
949 static ushort IUnaryPlusOperators<ushort, ushort>.operator +(ushort value)
950 {
951 return value;
952 }
953}
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 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 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 Arg_MustBeUInt16
Definition SR.cs:306
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 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 IntPtr MaxValue
Definition IntPtr.cs:30
static ushort Parse(string s, NumberStyles style, IFormatProvider? provider)
Definition UInt16.cs:129
static bool TryParse(ReadOnlySpan< char > s, out ushort result)
Definition UInt16.cs:170
override bool Equals([NotNullWhen(true)] object? obj)
Definition UInt16.cs:56
static bool TryParse(ReadOnlySpan< char > s, NumberStyles style, IFormatProvider? provider, out ushort result)
Definition UInt16.cs:186
static ushort ushort Remainder INumber< ushort >. DivRem(ushort left, ushort right)
Definition UInt16.cs:708
static ushort Parse(string s, IFormatProvider? provider)
Definition UInt16.cs:120
int CompareTo(object? value)
Definition UInt16.cs:38
override string ToString()
Definition UInt16.cs:76
string ToString(string? format, IFormatProvider? provider)
Definition UInt16.cs:91
override int GetHashCode()
Definition UInt16.cs:71
static bool TryParse([NotNullWhen(true)] string? s, out ushort result)
Definition UInt16.cs:160
static ushort Parse(string s, NumberStyles style)
Definition UInt16.cs:110
bool Equals(ushort obj)
Definition UInt16.cs:66
bool TryFormat(Span< char > destination, out int charsWritten, ReadOnlySpan< char > format=default(ReadOnlySpan< char >), IFormatProvider? provider=null)
Definition UInt16.cs:96
const ushort MinValue
Definition UInt16.cs:18
static ushort Parse(string s)
Definition UInt16.cs:101
string ToString(string? format)
Definition UInt16.cs:86
static ushort Parse(ReadOnlySpan< char > s, NumberStyles style, NumberFormatInfo info)
Definition UInt16.cs:145
static ushort Parse(ReadOnlySpan< char > s, NumberStyles style=NumberStyles.Integer, IFormatProvider? provider=null)
Definition UInt16.cs:139
const ushort MaxValue
Definition UInt16.cs:16
static ushort Quotient
Definition UInt16.cs:708
readonly ushort m_value
Definition UInt16.cs:14
int CompareTo(ushort value)
Definition UInt16.cs:51
static bool TryParse(ReadOnlySpan< char > s, NumberStyles style, NumberFormatInfo info, out ushort result)
Definition UInt16.cs:192
static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out ushort result)
Definition UInt16.cs:175
string ToString(IFormatProvider? provider)
Definition UInt16.cs:81
TypeCode GetTypeCode()
Definition UInt16.cs:203
static UIntPtr MaxValue
Definition UIntPtr.cs:31