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