From 3f96417081440512695831465378e6bf6b24cd6d Mon Sep 17 00:00:00 2001 From: Adam Dernis Date: Wed, 15 Oct 2025 05:01:41 +0300 Subject: [PATCH] Added allow ref struct anti-constraint to Generic ThrowHelpers --- .../ThrowHelper.Generic.cs | 243 ++++++++++++++++++ 1 file changed, 243 insertions(+) diff --git a/src/CommunityToolkit.Diagnostics/ThrowHelper.Generic.cs b/src/CommunityToolkit.Diagnostics/ThrowHelper.Generic.cs index 82b74fe5f..619a35a46 100644 --- a/src/CommunityToolkit.Diagnostics/ThrowHelper.Generic.cs +++ b/src/CommunityToolkit.Diagnostics/ThrowHelper.Generic.cs @@ -22,6 +22,9 @@ partial class ThrowHelper /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArrayTypeMismatchException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArrayTypeMismatchException(); } @@ -35,6 +38,9 @@ public static T ThrowArrayTypeMismatchException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArrayTypeMismatchException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArrayTypeMismatchException(message); } @@ -49,6 +55,9 @@ public static T ThrowArrayTypeMismatchException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArrayTypeMismatchException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArrayTypeMismatchException(message, innerException); } @@ -61,6 +70,9 @@ public static T ThrowArrayTypeMismatchException(string? message, Exception? i /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentException(); } @@ -74,6 +86,9 @@ public static T ThrowArgumentException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentException(message); } @@ -88,6 +103,9 @@ public static T ThrowArgumentException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentException(message, innerException); } @@ -102,6 +120,9 @@ public static T ThrowArgumentException(string? message, Exception? innerExcep /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentException(string? name, string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentException(message, name); } @@ -117,6 +138,9 @@ public static T ThrowArgumentException(string? name, string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentException(string? name, string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentException(message, name, innerException); } @@ -129,6 +153,9 @@ public static T ThrowArgumentException(string? name, string? message, Excepti /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentNullException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentNullException(); } @@ -142,6 +169,9 @@ public static T ThrowArgumentNullException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentNullException(string? name) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentNullException(name); } @@ -156,6 +186,9 @@ public static T ThrowArgumentNullException(string? name) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentNullException(string? name, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentNullException(name, innerException); } @@ -170,6 +203,9 @@ public static T ThrowArgumentNullException(string? name, Exception? innerExce /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentNullException(string? name, string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentNullException(name, message); } @@ -182,6 +218,9 @@ public static T ThrowArgumentNullException(string? name, string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentOutOfRangeException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentOutOfRangeException(); } @@ -195,6 +234,9 @@ public static T ThrowArgumentOutOfRangeException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentOutOfRangeException(string? name) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentOutOfRangeException(name); } @@ -209,6 +251,9 @@ public static T ThrowArgumentOutOfRangeException(string? name) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentOutOfRangeException(string? name, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentOutOfRangeException(name, innerException); } @@ -223,6 +268,9 @@ public static T ThrowArgumentOutOfRangeException(string? name, Exception? inn /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentOutOfRangeException(string? name, string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentOutOfRangeException(name, message); } @@ -238,6 +286,9 @@ public static T ThrowArgumentOutOfRangeException(string? name, string? messag /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowArgumentOutOfRangeException(string? name, object? value, string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ArgumentOutOfRangeException(name, value, message); } @@ -250,6 +301,9 @@ public static T ThrowArgumentOutOfRangeException(string? name, object? value, /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowCOMException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new COMException(); } @@ -263,6 +317,9 @@ public static T ThrowCOMException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowCOMException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new COMException(message); } @@ -277,6 +334,9 @@ public static T ThrowCOMException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowCOMException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new COMException(message, innerException); } @@ -291,6 +351,9 @@ public static T ThrowCOMException(string? message, Exception? innerException) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowCOMException(string? message, int error) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new COMException(message, error); } @@ -303,6 +366,9 @@ public static T ThrowCOMException(string? message, int error) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowExternalException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ExternalException(); } @@ -316,6 +382,9 @@ public static T ThrowExternalException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowExternalException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ExternalException(message); } @@ -330,6 +399,9 @@ public static T ThrowExternalException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowExternalException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ExternalException(message, innerException); } @@ -344,6 +416,9 @@ public static T ThrowExternalException(string? message, Exception? innerExcep /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowExternalException(string? message, int error) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ExternalException(message, error); } @@ -356,6 +431,9 @@ public static T ThrowExternalException(string? message, int error) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowFormatException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new FormatException(); } @@ -369,6 +447,9 @@ public static T ThrowFormatException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowFormatException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new FormatException(message); } @@ -383,6 +464,9 @@ public static T ThrowFormatException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowFormatException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new FormatException(message, innerException); } @@ -395,6 +479,9 @@ public static T ThrowFormatException(string? message, Exception? innerExcepti /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowInsufficientMemoryException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new InsufficientMemoryException(); } @@ -408,6 +495,9 @@ public static T ThrowInsufficientMemoryException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowInsufficientMemoryException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new InsufficientMemoryException(message); } @@ -422,6 +512,9 @@ public static T ThrowInsufficientMemoryException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowInsufficientMemoryException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new InsufficientMemoryException(message, innerException); } @@ -434,6 +527,9 @@ public static T ThrowInsufficientMemoryException(string? message, Exception? /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowInvalidDataException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new InvalidDataException(); } @@ -447,6 +543,9 @@ public static T ThrowInvalidDataException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowInvalidDataException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new InvalidDataException(message); } @@ -461,6 +560,9 @@ public static T ThrowInvalidDataException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowInvalidDataException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new InvalidDataException(message, innerException); } @@ -473,6 +575,9 @@ public static T ThrowInvalidDataException(string? message, Exception? innerEx /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowInvalidOperationException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new InvalidOperationException(); } @@ -486,6 +591,9 @@ public static T ThrowInvalidOperationException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowInvalidOperationException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new InvalidOperationException(message); } @@ -500,6 +608,9 @@ public static T ThrowInvalidOperationException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowInvalidOperationException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new InvalidOperationException(message, innerException); } @@ -512,6 +623,9 @@ public static T ThrowInvalidOperationException(string? message, Exception? in /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowLockRecursionException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new LockRecursionException(); } @@ -525,6 +639,9 @@ public static T ThrowLockRecursionException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowLockRecursionException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new LockRecursionException(message); } @@ -539,6 +656,9 @@ public static T ThrowLockRecursionException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowLockRecursionException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new LockRecursionException(message, innerException); } @@ -551,6 +671,9 @@ public static T ThrowLockRecursionException(string? message, Exception? inner /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingFieldException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingFieldException(); } @@ -564,6 +687,9 @@ public static T ThrowMissingFieldException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingFieldException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingFieldException(message); } @@ -578,6 +704,9 @@ public static T ThrowMissingFieldException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingFieldException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingFieldException(message, innerException); } @@ -592,6 +721,9 @@ public static T ThrowMissingFieldException(string? message, Exception? innerE /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingFieldException(string? className, string? fieldName) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingFieldException(className, fieldName); } @@ -604,6 +736,9 @@ public static T ThrowMissingFieldException(string? className, string? fieldNa /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingMemberException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingMemberException(); } @@ -617,6 +752,9 @@ public static T ThrowMissingMemberException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingMemberException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingMemberException(message); } @@ -631,6 +769,9 @@ public static T ThrowMissingMemberException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingMemberException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingMemberException(message, innerException); } @@ -645,6 +786,9 @@ public static T ThrowMissingMemberException(string? message, Exception? inner /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingMemberException(string? className, string? memberName) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingMemberException(className, memberName); } @@ -657,6 +801,9 @@ public static T ThrowMissingMemberException(string? className, string? member /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingMethodException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingMethodException(); } @@ -670,6 +817,9 @@ public static T ThrowMissingMethodException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingMethodException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingMethodException(message); } @@ -684,6 +834,9 @@ public static T ThrowMissingMethodException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingMethodException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingMethodException(message, innerException); } @@ -698,6 +851,9 @@ public static T ThrowMissingMethodException(string? message, Exception? inner /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowMissingMethodException(string? className, string? methodName) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new MissingMethodException(className, methodName); } @@ -710,6 +866,9 @@ public static T ThrowMissingMethodException(string? className, string? method /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowNotSupportedException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new NotSupportedException(); } @@ -723,6 +882,9 @@ public static T ThrowNotSupportedException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowNotSupportedException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new NotSupportedException(message); } @@ -737,6 +899,9 @@ public static T ThrowNotSupportedException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowNotSupportedException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new NotSupportedException(message, innerException); } @@ -750,6 +915,9 @@ public static T ThrowNotSupportedException(string? message, Exception? innerE /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowObjectDisposedException(string? objectName) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ObjectDisposedException(objectName); } @@ -764,6 +932,9 @@ public static T ThrowObjectDisposedException(string? objectName) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowObjectDisposedException(string? objectName, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ObjectDisposedException(objectName, innerException); } @@ -778,6 +949,9 @@ public static T ThrowObjectDisposedException(string? objectName, Exception? i /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowObjectDisposedException(string? objectName, string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new ObjectDisposedException(objectName, message); } @@ -790,6 +964,9 @@ public static T ThrowObjectDisposedException(string? objectName, string? mess /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowOperationCanceledException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new OperationCanceledException(); } @@ -803,6 +980,9 @@ public static T ThrowOperationCanceledException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowOperationCanceledException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new OperationCanceledException(message); } @@ -817,6 +997,9 @@ public static T ThrowOperationCanceledException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowOperationCanceledException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new OperationCanceledException(message, innerException); } @@ -830,6 +1013,9 @@ public static T ThrowOperationCanceledException(string? message, Exception? i /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowOperationCanceledException(CancellationToken token) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new OperationCanceledException(token); } @@ -844,6 +1030,9 @@ public static T ThrowOperationCanceledException(CancellationToken token) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowOperationCanceledException(string? message, CancellationToken token) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new OperationCanceledException(message, token); } @@ -859,6 +1048,9 @@ public static T ThrowOperationCanceledException(string? message, Cancellation /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowOperationCanceledException(string? message, Exception? innerException, CancellationToken token) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new OperationCanceledException(message, innerException, token); } @@ -871,6 +1063,9 @@ public static T ThrowOperationCanceledException(string? message, Exception? i /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowPlatformNotSupportedException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new PlatformNotSupportedException(); } @@ -884,6 +1079,9 @@ public static T ThrowPlatformNotSupportedException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowPlatformNotSupportedException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new PlatformNotSupportedException(message); } @@ -898,6 +1096,9 @@ public static T ThrowPlatformNotSupportedException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowPlatformNotSupportedException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new PlatformNotSupportedException(message, innerException); } @@ -910,6 +1111,9 @@ public static T ThrowPlatformNotSupportedException(string? message, Exception /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowSynchronizationLockException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new SynchronizationLockException(); } @@ -923,6 +1127,9 @@ public static T ThrowSynchronizationLockException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowSynchronizationLockException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new SynchronizationLockException(message); } @@ -937,6 +1144,9 @@ public static T ThrowSynchronizationLockException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowSynchronizationLockException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new SynchronizationLockException(message, innerException); } @@ -949,6 +1159,9 @@ public static T ThrowSynchronizationLockException(string? message, Exception? /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowTimeoutException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new TimeoutException(); } @@ -962,6 +1175,9 @@ public static T ThrowTimeoutException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowTimeoutException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new TimeoutException(message); } @@ -976,6 +1192,9 @@ public static T ThrowTimeoutException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowTimeoutException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new TimeoutException(message, innerException); } @@ -988,6 +1207,9 @@ public static T ThrowTimeoutException(string? message, Exception? innerExcept /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowUnauthorizedAccessException() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new UnauthorizedAccessException(); } @@ -1001,6 +1223,9 @@ public static T ThrowUnauthorizedAccessException() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowUnauthorizedAccessException(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new UnauthorizedAccessException(message); } @@ -1015,6 +1240,9 @@ public static T ThrowUnauthorizedAccessException(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowUnauthorizedAccessException(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new UnauthorizedAccessException(message, innerException); } @@ -1027,6 +1255,9 @@ public static T ThrowUnauthorizedAccessException(string? message, Exception? /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowWin32Exception() + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new Win32Exception(); } @@ -1040,6 +1271,9 @@ public static T ThrowWin32Exception() /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowWin32Exception(int error) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new Win32Exception(error); } @@ -1054,6 +1288,9 @@ public static T ThrowWin32Exception(int error) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowWin32Exception(int error, string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new Win32Exception(error, message); } @@ -1067,6 +1304,9 @@ public static T ThrowWin32Exception(int error, string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowWin32Exception(string? message) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new Win32Exception(message); } @@ -1081,6 +1321,9 @@ public static T ThrowWin32Exception(string? message) /// This method always throws, so it actually never returns a value. [DoesNotReturn] public static T ThrowWin32Exception(string? message, Exception? innerException) + #if NET9_0_OR_GREATER + where T : allows ref struct + #endif { throw new Win32Exception(message, innerException); }