From 6ace41b2b854f4b93f18a3d81989837ec85b5b7c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 Nov 2020 13:29:15 +0100 Subject: [PATCH 01/12] Minor code tweaks --- .../Diagnostics/Guard.Comparable.Generic.cs | 49 ++++++------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs index 8741b4c15db..94dc8bb7aa1 100644 --- a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs @@ -112,10 +112,7 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) // so that only the right one will actually be translated into native code. if (sizeof(T) == 1) { - byte valueByte = Unsafe.As(ref value); - byte targetByte = Unsafe.As(ref target); - - if (valueByte == targetByte) + if (*(byte*)&value == *(byte*)&target) { return; } @@ -124,10 +121,7 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) } else if (sizeof(T) == 2) { - ushort valueUShort = Unsafe.As(ref value); - ushort targetUShort = Unsafe.As(ref target); - - if (valueUShort == targetUShort) + if (*(ushort*)&value == *(ushort*)&target) { return; } @@ -136,10 +130,7 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) } else if (sizeof(T) == 4) { - uint valueUInt = Unsafe.As(ref value); - uint targetUInt = Unsafe.As(ref target); - - if (valueUInt == targetUInt) + if (*(uint*)&value == *(uint*)&target) { return; } @@ -148,10 +139,7 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) } else if (sizeof(T) == 8) { - ulong valueULong = Unsafe.As(ref value); - ulong targetULong = Unsafe.As(ref target); - - if (Bit64Compare(ref valueULong, ref targetULong)) + if (Bit64Compare(*(ulong*)&value, *(ulong*)&target)) { return; } @@ -160,26 +148,20 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) } else if (sizeof(T) == 16) { - ulong valueULong0 = Unsafe.As(ref value); - ulong targetULong0 = Unsafe.As(ref target); + ulong* p0 = (ulong*)&value; + ulong* p1 = (ulong*)⌖ - if (Bit64Compare(ref valueULong0, ref targetULong0)) + if (Bit64Compare(p0[0], p1[0]) && Bit64Compare(p0[1], p1[1])) { - ulong valueULong1 = Unsafe.Add(ref Unsafe.As(ref value), 1); - ulong targetULong1 = Unsafe.Add(ref Unsafe.As(ref target), 1); - - if (Bit64Compare(ref valueULong1, ref targetULong1)) - { - return; - } + return; } ThrowHelper.ThrowArgumentExceptionForBitwiseEqualTo(value, target, name); } else { - Span valueBytes = new Span(Unsafe.AsPointer(ref value), sizeof(T)); - Span targetBytes = new Span(Unsafe.AsPointer(ref target), sizeof(T)); + Span valueBytes = new Span(&value, sizeof(T)); + Span targetBytes = new Span(&target, sizeof(T)); if (valueBytes.SequenceEqual(targetBytes)) { @@ -193,16 +175,15 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) // Compares 64 bits of data from two given memory locations for bitwise equality [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static unsafe bool Bit64Compare(ref ulong left, ref ulong right) + private static unsafe bool Bit64Compare(ulong left, ulong right) { // Handles 32 bit case, because using ulong is inefficient - if (sizeof(IntPtr) == 4) + if (sizeof(nint) == 4) { - ref int r0 = ref Unsafe.As(ref left); - ref int r1 = ref Unsafe.As(ref right); + uint* p0 = (uint*)&left; + uint* p1 = (uint*)&right; - return r0 == r1 && - Unsafe.Add(ref r0, 1) == Unsafe.Add(ref r1, 1); + return p0[0] == p1[0] && p0[1] == p1[1]; } return left == right; From 8c01abc379c194dcf5dfd24943d5946af085e49d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 Nov 2020 14:50:39 +0100 Subject: [PATCH 02/12] Added nint/nuint comparable Guard overloads --- .../Generated/Guard.Comparable.Numeric.g.cs | 502 ++++++++++++++++++ .../Generated/Guard.Comparable.Numeric.tt | 63 +-- .../Diagnostics/Generated/TypeInfo.ttinclude | 18 +- 3 files changed, 551 insertions(+), 32 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs index 8f911a4cd41..431c65f2aa6 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs @@ -3026,5 +3026,507 @@ public static void IsNotBetweenOrEqualTo(decimal value, decimal minimum, decimal ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(value, minimum, maximum, name); } + + /// + /// Asserts that the input value must be equal to a specified value. + /// + /// The input value to test. + /// The target value to test for. + /// The name of the input parameter being tested. + /// Thrown if is != . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsEqualTo(nint value, nint target, string name) + { + if (value == target) + { + return; + } + + ThrowHelper.ThrowArgumentExceptionForIsEqualTo(value, target, name); + } + + /// + /// Asserts that the input value must be not equal to a specified value. + /// + /// The input value to test. + /// The target value to test for. + /// The name of the input parameter being tested. + /// Thrown if is == . + /// The method is generic to avoid boxing the parameters, if they are value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotEqualTo(nint value, nint target, string name) + { + if (value != target) + { + return; + } + + ThrowHelper.ThrowArgumentExceptionForIsNotEqualTo(value, target, name); + } + + /// + /// Asserts that the input value must be less than a specified value. + /// + /// The input value to test. + /// The exclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is >= . + /// The method is generic to avoid boxing the parameters, if they are value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsLessThan(nint value, nint maximum, string name) + { + if (value < maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsLessThan(value, maximum, name); + } + + /// + /// Asserts that the input value must be less than or equal to a specified value. + /// + /// The input value to test. + /// The inclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is > . + /// The method is generic to avoid boxing the parameters, if they are value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsLessThanOrEqualTo(nint value, nint maximum, string name) + { + if (value <= maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(value, maximum, name); + } + + /// + /// Asserts that the input value must be greater than a specified value. + /// + /// The input value to test. + /// The exclusive minimum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is <= . + /// The method is generic to avoid boxing the parameters, if they are value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsGreaterThan(nint value, nint minimum, string name) + { + if (value > minimum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsGreaterThan(value, minimum, name); + } + + /// + /// Asserts that the input value must be greater than or equal to a specified value. + /// + /// The input value to test. + /// The inclusive minimum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is < . + /// The method is generic to avoid boxing the parameters, if they are value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsGreaterThanOrEqualTo(nint value, nint minimum, string name) + { + if (value >= minimum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(value, minimum, name); + } + + /// + /// Asserts that the input value must be in a given range. + /// + /// The input value to test. + /// The inclusive minimum value that is accepted. + /// The exclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is < or >= . + /// + /// This API asserts the equivalent of " in [, )", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsInRange(nint value, nint minimum, nint maximum, string name) + { + if (value >= minimum && value < maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRange(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must not be in a given range. + /// + /// The input value to test. + /// The inclusive minimum value that is accepted. + /// The exclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is >= or < . + /// + /// This API asserts the equivalent of " not in [, )", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotInRange(nint value, nint minimum, nint maximum, string name) + { + if (value < minimum || value >= maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRange(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must be in a given interval. + /// + /// The input value to test. + /// The exclusive minimum value that is accepted. + /// The exclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is <= or >= . + /// + /// This API asserts the equivalent of " in (, )", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsBetween(nint value, nint minimum, nint maximum, string name) + { + if (value > minimum && value < maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsBetween(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must not be in a given interval. + /// + /// The input value to test. + /// The exclusive minimum value that is accepted. + /// The exclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is > or < . + /// + /// This API asserts the equivalent of " not in (, )", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotBetween(nint value, nint minimum, nint maximum, string name) + { + if (value <= minimum || value >= maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotBetween(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must be in a given interval. + /// + /// The input value to test. + /// The inclusive minimum value that is accepted. + /// The inclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is < or > . + /// + /// This API asserts the equivalent of " in [, ]", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsBetweenOrEqualTo(nint value, nint minimum, nint maximum, string name) + { + if (value >= minimum && value <= maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must not be in a given interval. + /// + /// The input value to test. + /// The inclusive minimum value that is accepted. + /// The inclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is >= or <= . + /// + /// This API asserts the equivalent of " not in [, ]", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotBetweenOrEqualTo(nint value, nint minimum, nint maximum, string name) + { + if (value < minimum || value > maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must be equal to a specified value. + /// + /// The input value to test. + /// The target value to test for. + /// The name of the input parameter being tested. + /// Thrown if is != . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsEqualTo(nuint value, nuint target, string name) + { + if (value == target) + { + return; + } + + ThrowHelper.ThrowArgumentExceptionForIsEqualTo(value, target, name); + } + + /// + /// Asserts that the input value must be not equal to a specified value. + /// + /// The input value to test. + /// The target value to test for. + /// The name of the input parameter being tested. + /// Thrown if is == . + /// The method is generic to avoid boxing the parameters, if they are value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotEqualTo(nuint value, nuint target, string name) + { + if (value != target) + { + return; + } + + ThrowHelper.ThrowArgumentExceptionForIsNotEqualTo(value, target, name); + } + + /// + /// Asserts that the input value must be less than a specified value. + /// + /// The input value to test. + /// The exclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is >= . + /// The method is generic to avoid boxing the parameters, if they are value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsLessThan(nuint value, nuint maximum, string name) + { + if (value < maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsLessThan(value, maximum, name); + } + + /// + /// Asserts that the input value must be less than or equal to a specified value. + /// + /// The input value to test. + /// The inclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is > . + /// The method is generic to avoid boxing the parameters, if they are value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsLessThanOrEqualTo(nuint value, nuint maximum, string name) + { + if (value <= maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(value, maximum, name); + } + + /// + /// Asserts that the input value must be greater than a specified value. + /// + /// The input value to test. + /// The exclusive minimum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is <= . + /// The method is generic to avoid boxing the parameters, if they are value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsGreaterThan(nuint value, nuint minimum, string name) + { + if (value > minimum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsGreaterThan(value, minimum, name); + } + + /// + /// Asserts that the input value must be greater than or equal to a specified value. + /// + /// The input value to test. + /// The inclusive minimum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is < . + /// The method is generic to avoid boxing the parameters, if they are value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsGreaterThanOrEqualTo(nuint value, nuint minimum, string name) + { + if (value >= minimum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(value, minimum, name); + } + + /// + /// Asserts that the input value must be in a given range. + /// + /// The input value to test. + /// The inclusive minimum value that is accepted. + /// The exclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is < or >= . + /// + /// This API asserts the equivalent of " in [, )", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsInRange(nuint value, nuint minimum, nuint maximum, string name) + { + if (value >= minimum && value < maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRange(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must not be in a given range. + /// + /// The input value to test. + /// The inclusive minimum value that is accepted. + /// The exclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is >= or < . + /// + /// This API asserts the equivalent of " not in [, )", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotInRange(nuint value, nuint minimum, nuint maximum, string name) + { + if (value < minimum || value >= maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRange(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must be in a given interval. + /// + /// The input value to test. + /// The exclusive minimum value that is accepted. + /// The exclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is <= or >= . + /// + /// This API asserts the equivalent of " in (, )", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsBetween(nuint value, nuint minimum, nuint maximum, string name) + { + if (value > minimum && value < maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsBetween(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must not be in a given interval. + /// + /// The input value to test. + /// The exclusive minimum value that is accepted. + /// The exclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is > or < . + /// + /// This API asserts the equivalent of " not in (, )", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotBetween(nuint value, nuint minimum, nuint maximum, string name) + { + if (value <= minimum || value >= maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotBetween(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must be in a given interval. + /// + /// The input value to test. + /// The inclusive minimum value that is accepted. + /// The inclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is < or > . + /// + /// This API asserts the equivalent of " in [, ]", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsBetweenOrEqualTo(nuint value, nuint minimum, nuint maximum, string name) + { + if (value >= minimum && value <= maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(value, minimum, maximum, name); + } + + /// + /// Asserts that the input value must not be in a given interval. + /// + /// The input value to test. + /// The inclusive minimum value that is accepted. + /// The inclusive maximum value that is accepted. + /// The name of the input parameter being tested. + /// Thrown if is >= or <= . + /// + /// This API asserts the equivalent of " not in [, ]", using arithmetic notation. + /// The method is generic to avoid boxing the parameters, if they are value types. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotBetweenOrEqualTo(nuint value, nuint minimum, nuint maximum, string name) + { + if (value < minimum || value > maximum) + { + return; + } + + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(value, minimum, maximum, name); + } } } diff --git a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt index 4977a75660e..7e0bd9db3b7 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt @@ -13,14 +13,15 @@ namespace Microsoft.Toolkit.Diagnostics public static partial class Guard { <# -GenerateTextForItems(NumericTypes, type => +GenerateTextForItems(NumericTypes, typeInfo => { + var (type, prefix) = typeInfo; #> /// /// Asserts that the input value must be equal to a specified value. /// - /// The input value to test. - /// The target value to test for. + /// The input ="<#=type#>"/> value to test. + /// The target ="<#=type#>"/> value to test for. /// The name of the input parameter being tested. /// Thrown if is != . [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -37,8 +38,8 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must be not equal to a specified value. /// - /// The input value to test. - /// The target value to test for. + /// The input ="<#=type#>"/> value to test. + /// The target ="<#=type#>"/> value to test for. /// The name of the input parameter being tested. /// Thrown if is == . /// The method is generic to avoid boxing the parameters, if they are value types. @@ -56,8 +57,8 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must be less than a specified value. /// - /// The input value to test. - /// The exclusive maximum value that is accepted. + /// The input ="<#=type#>"/> value to test. + /// The exclusive maximum ="<#=type#>"/> value that is accepted. /// The name of the input parameter being tested. /// Thrown if is >= . /// The method is generic to avoid boxing the parameters, if they are value types. @@ -75,8 +76,8 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must be less than or equal to a specified value. /// - /// The input value to test. - /// The inclusive maximum value that is accepted. + /// The input ="<#=type#>"/> value to test. + /// The inclusive maximum ="<#=type#>"/> value that is accepted. /// The name of the input parameter being tested. /// Thrown if is > . /// The method is generic to avoid boxing the parameters, if they are value types. @@ -94,8 +95,8 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must be greater than a specified value. /// - /// The input value to test. - /// The exclusive minimum value that is accepted. + /// The input ="<#=type#>"/> value to test. + /// The exclusive minimum ="<#=type#>"/> value that is accepted. /// The name of the input parameter being tested. /// Thrown if is <= . /// The method is generic to avoid boxing the parameters, if they are value types. @@ -113,8 +114,8 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must be greater than or equal to a specified value. /// - /// The input value to test. - /// The inclusive minimum value that is accepted. + /// The input ="<#=type#>"/> value to test. + /// The inclusive minimum ="<#=type#>"/> value that is accepted. /// The name of the input parameter being tested. /// Thrown if is < . /// The method is generic to avoid boxing the parameters, if they are value types. @@ -132,9 +133,9 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must be in a given range. /// - /// The input value to test. - /// The inclusive minimum value that is accepted. - /// The exclusive maximum value that is accepted. + /// The input ="<#=type#>"/> value to test. + /// The inclusive minimum ="<#=type#>"/> value that is accepted. + /// The exclusive maximum ="<#=type#>"/> value that is accepted. /// The name of the input parameter being tested. /// Thrown if is < or >= . /// @@ -155,9 +156,9 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must not be in a given range. /// - /// The input value to test. - /// The inclusive minimum value that is accepted. - /// The exclusive maximum value that is accepted. + /// The input ="<#=type#>"/> value to test. + /// The inclusive minimum ="<#=type#>"/> value that is accepted. + /// The exclusive maximum ="<#=type#>"/> value that is accepted. /// The name of the input parameter being tested. /// Thrown if is >= or < . /// @@ -178,9 +179,9 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must be in a given interval. /// - /// The input value to test. - /// The exclusive minimum value that is accepted. - /// The exclusive maximum value that is accepted. + /// The input ="<#=type#>"/> value to test. + /// The exclusive minimum ="<#=type#>"/> value that is accepted. + /// The exclusive maximum ="<#=type#>"/> value that is accepted. /// The name of the input parameter being tested. /// Thrown if is <= or >= . /// @@ -201,9 +202,9 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must not be in a given interval. /// - /// The input value to test. - /// The exclusive minimum value that is accepted. - /// The exclusive maximum value that is accepted. + /// The input ="<#=type#>"/> value to test. + /// The exclusive minimum ="<#=type#>"/> value that is accepted. + /// The exclusive maximum ="<#=type#>"/> value that is accepted. /// The name of the input parameter being tested. /// Thrown if is > or < . /// @@ -224,9 +225,9 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must be in a given interval. /// - /// The input value to test. - /// The inclusive minimum value that is accepted. - /// The inclusive maximum value that is accepted. + /// The input ="<#=type#>"/> value to test. + /// The inclusive minimum ="<#=type#>"/> value that is accepted. + /// The inclusive maximum ="<#=type#>"/> value that is accepted. /// The name of the input parameter being tested. /// Thrown if is < or > . /// @@ -247,9 +248,9 @@ GenerateTextForItems(NumericTypes, type => /// /// Asserts that the input value must not be in a given interval. /// - /// The input value to test. - /// The inclusive minimum value that is accepted. - /// The inclusive maximum value that is accepted. + /// The input ="<#=type#>"/> value to test. + /// The inclusive minimum ="<#=type#>"/> value that is accepted. + /// The inclusive maximum ="<#=type#>"/> value that is accepted. /// The name of the input parameter being tested. /// Thrown if is >= or <= . /// diff --git a/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude b/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude index 1bcffa5513f..52350d1eb12 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude +++ b/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude @@ -81,7 +81,23 @@ /// /// Gets the list of available numeric types to generate APIs for /// - static readonly IReadOnlyList NumericTypes = new[] { "byte", "sbyte", "short", "ushort", "char", "int", "uint", "float", "long", "ulong", "double", "decimal" }; + static readonly IReadOnlyList<(string Name, string Prefix)> NumericTypes = new[] + { + ("byte", "cref"), + ("sbyte", "cref"), + ("short", "cref"), + ("ushort", "cref"), + ("char", "cref"), + ("int", "cref"), + ("uint", "cref"), + ("float", "cref"), + ("long", "cref"), + ("ulong", "cref"), + ("double", "cref"), + ("decimal", "cref"), + ("nint", "langword"), + ("nuint", "langword") + }; /// /// Generates text for a given sequence of items, automatically adding the necessary spacing From 0258fec531a6f7071f0b0578addcb2ad91acee87 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 Nov 2020 15:28:42 +0100 Subject: [PATCH 03/12] Refactored Guard.IsCloseTo unit tests --- .../Test_Guard.Comparable.Numeric.cs | 99 ++++++++----------- 1 file changed, 43 insertions(+), 56 deletions(-) diff --git a/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs b/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs index a2df22682cd..089cc190b58 100644 --- a/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs +++ b/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics.CodeAnalysis; using Microsoft.Toolkit.Diagnostics; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -13,88 +12,76 @@ public partial class Test_Guard { [TestCategory("Guard")] [TestMethod] - public void Test_Guard_IsCloseToInt_Ok() + [DataRow(0, 20, 10u, false)] + [DataRow(0, 6, 5u, false)] + [DataRow(0, int.MaxValue, 500u, false)] + [DataRow(-500, -530, 10u, false)] + [DataRow(1000, 800, 100u, false)] + [DataRow(int.MaxValue, int.MaxValue - 10, 7u, false)] + [DataRow(int.MinValue, int.MaxValue, (uint)int.MaxValue, false)] + [DataRow(0, 5, 10u, true)] + [DataRow(0, 5, 5u, true)] + [DataRow(0, int.MaxValue, (uint)int.MaxValue, true)] + [DataRow(-500, -530, 50u, true)] + [DataRow(1000, 800, 200u, true)] + [DataRow(int.MaxValue, int.MaxValue - 10, 10u, true)] + public void Test_Guard_IsCloseToInt(int value, int target, uint delta, bool isClose) { - Guard.IsCloseTo(0, 5, 10, nameof(Test_Guard_IsCloseToInt_Ok)); - Guard.IsCloseTo(0, 5, 5, nameof(Test_Guard_IsCloseToInt_Ok)); - Guard.IsCloseTo(0, int.MaxValue, int.MaxValue, nameof(Test_Guard_IsCloseToInt_Ok)); - Guard.IsCloseTo(-500, -530, 50, nameof(Test_Guard_IsCloseToInt_Ok)); - Guard.IsCloseTo(1000, 800, 200, nameof(Test_Guard_IsCloseToInt_Ok)); - Guard.IsCloseTo(int.MaxValue, int.MaxValue - 10, 10, nameof(Test_Guard_IsCloseToInt_Ok)); - } - - [TestCategory("Guard")] - [TestMethod] - [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1000", Justification = "Value tuple")] - public void Test_Guard_IsCloseToInt_Fail() - { - foreach (var item in new (int Value, int Target, uint Delta)[] - { - (0, 20, 10), - (0, 6, 5), - (0, int.MaxValue, 500), - (-500, -530, 10), - (1000, 800, 100), - (int.MaxValue, int.MaxValue - 10, 7), - (int.MinValue, int.MaxValue, int.MaxValue) - }) + void Test(int value, int target) { - bool fail = false; + bool isFailed = false; try { - Guard.IsCloseTo(item.Value, item.Target, item.Delta, nameof(Test_Guard_IsCloseToInt_Fail)); + Guard.IsCloseTo(value, target, delta, nameof(Test_Guard_IsCloseToInt)); } catch (ArgumentException) { - fail = true; + isFailed = true; } - Assert.IsTrue(fail, $"IsCloseTo didn't fail with {item}"); + Assert.AreEqual(isClose, !isFailed); } - } - [TestCategory("Guard")] - [TestMethod] - public void Test_Guard_IsCloseToFloat_Ok() - { - Guard.IsCloseTo(0f, 5, 10, nameof(Test_Guard_IsCloseToFloat_Ok)); - Guard.IsCloseTo(0f, 5, 5, nameof(Test_Guard_IsCloseToFloat_Ok)); - Guard.IsCloseTo(0f, float.MaxValue, float.MaxValue, nameof(Test_Guard_IsCloseToFloat_Ok)); - Guard.IsCloseTo(-500f, -530, 50, nameof(Test_Guard_IsCloseToFloat_Ok)); - Guard.IsCloseTo(1000f, 800, 200, nameof(Test_Guard_IsCloseToFloat_Ok)); - Guard.IsCloseTo(float.MaxValue, float.MaxValue - 10, 10, nameof(Test_Guard_IsCloseToFloat_Ok)); + Test(value, target); + Test(target, value); } [TestCategory("Guard")] [TestMethod] - [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1000", Justification = "Value tuple")] - public void Test_Guard_IsCloseToFloat_Fail() + [DataRow(0f, 20f, 10f, false)] + [DataRow(0f, 6f, 5f, false)] + [DataRow(0f, float.MaxValue, 500f, false)] + [DataRow(-500f, -530f, 10f, false)] + [DataRow(1000f, 800f, 100f, false)] + [DataRow(float.MaxValue, float.MaxValue / 2, 7f, false)] + [DataRow(float.MinValue, float.MaxValue, float.MaxValue, false)] + [DataRow(0f, 5f, 10f, true)] + [DataRow(0f, 5f, 5f, true)] + [DataRow(0f, float.MaxValue, float.MaxValue, true)] + [DataRow(-500f, -530f, 50f, true)] + [DataRow(1000f, 800f, 200f, true)] + [DataRow(float.MaxValue, float.MaxValue - 10, 10f, true)] + public void Test_Guard_IsCloseToFloat(float value, float target, float delta, bool isClose) { - foreach (var item in new (float Value, float Target, float Delta)[] - { - (0, 20, 10), - (0, 6, 5), - (0, float.MaxValue, 500), - (-500, -530, 10), - (1000, 800, 100), - (float.MaxValue, float.MaxValue / 2, 7), - (float.MinValue, float.MaxValue, float.MaxValue) - }) + void Test(float value, float target) { - bool fail = false; + bool isFailed = false; try { - Guard.IsCloseTo(item.Value, item.Target, item.Delta, nameof(Test_Guard_IsCloseToFloat_Fail)); + Guard.IsCloseTo(value, target, delta, nameof(Test_Guard_IsCloseToInt)); } catch (ArgumentException) { - fail = true; + isFailed = true; } - Assert.IsTrue(fail, $"IsCloseTo didn't fail with {item}"); + Assert.AreEqual(isClose, !isFailed); } + + Test(value, target); + Test(target, value); } } } From a412d31300f7a22418e92de55d5e0e28a560aa0f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 Nov 2020 15:41:36 +0100 Subject: [PATCH 04/12] Improved IsCloseTo unit tests --- .../Test_Guard.Comparable.Numeric.cs | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs b/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs index 089cc190b58..831990a409c 100644 --- a/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs +++ b/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs @@ -25,7 +25,7 @@ public partial class Test_Guard [DataRow(-500, -530, 50u, true)] [DataRow(1000, 800, 200u, true)] [DataRow(int.MaxValue, int.MaxValue - 10, 10u, true)] - public void Test_Guard_IsCloseToInt(int value, int target, uint delta, bool isClose) + public void Test_Guard_IsCloseOrNotToInt(int value, int target, uint delta, bool isClose) { void Test(int value, int target) { @@ -33,7 +33,7 @@ void Test(int value, int target) try { - Guard.IsCloseTo(value, target, delta, nameof(Test_Guard_IsCloseToInt)); + Guard.IsCloseTo(value, target, delta, nameof(Test_Guard_IsCloseOrNotToInt)); } catch (ArgumentException) { @@ -41,6 +41,19 @@ void Test(int value, int target) } Assert.AreEqual(isClose, !isFailed); + + isFailed = false; + + try + { + Guard.IsNotCloseTo(value, target, delta, nameof(Test_Guard_IsCloseOrNotToInt)); + } + catch (ArgumentException) + { + isFailed = true; + } + + Assert.AreEqual(isClose, isFailed); } Test(value, target); @@ -70,7 +83,7 @@ void Test(float value, float target) try { - Guard.IsCloseTo(value, target, delta, nameof(Test_Guard_IsCloseToInt)); + Guard.IsCloseTo(value, target, delta, nameof(Test_Guard_IsCloseToFloat)); } catch (ArgumentException) { @@ -78,6 +91,19 @@ void Test(float value, float target) } Assert.AreEqual(isClose, !isFailed); + + isFailed = false; + + try + { + Guard.IsNotCloseTo(value, target, delta, nameof(Test_Guard_IsCloseToFloat)); + } + catch (ArgumentException) + { + isFailed = true; + } + + Assert.AreEqual(isClose, isFailed); } Test(value, target); From 84d447f5d413623a03f37707e3deed6e4a10171d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 Nov 2020 15:42:17 +0100 Subject: [PATCH 05/12] Codegen improvements to Guard.IsCloseTo --- .../Diagnostics/Guard.Comparable.Numeric.cs | 69 ++++++++++++++----- 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs index 45f0c00daed..302e255fa29 100644 --- a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs @@ -23,18 +23,18 @@ public static partial class Guard [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsCloseTo(int value, int target, uint delta, string name) { - // Cast to long before calculating the difference to avoid overflows - // when the values are at the two extremes of the supported range. - // Then cast to double to calculate the absolute value: this allows - // the JIT compiler to use AVX instructions on X64 CPUs instead of - // conditional jumps, which results in more efficient assembly code. - // The IEEE 754 specs guarantees that a 32 bit integer value can - // be stored within a double precision floating point value with - // no loss of precision, so the result will always be correct here. - // The difference is then cast to uint as that's the maximum possible - // value it can have, and comparing two 32 bit integer values - // results in shorter and slightly faster code than using doubles. - if ((uint)Math.Abs((double)((long)value - target)) <= delta) + uint difference; + + if (value >= target) + { + difference = (uint)(value - target); + } + else + { + difference = (uint)(target - value); + } + + if (difference <= delta) { return; } @@ -53,7 +53,18 @@ public static void IsCloseTo(int value, int target, uint delta, string name) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsNotCloseTo(int value, int target, uint delta, string name) { - if ((uint)Math.Abs((double)((long)value - target)) > delta) + uint difference; + + if (value >= target) + { + difference = (uint)(value - target); + } + else + { + difference = (uint)(target - value); + } + + if (difference > delta) { return; } @@ -69,12 +80,21 @@ public static void IsNotCloseTo(int value, int target, uint delta, string name) /// The maximum distance to allow between and . /// The name of the input parameter being tested. /// Thrown if ( - ) > . - [MethodImpl(MethodImplOptions.NoInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsCloseTo(long value, long target, ulong delta, string name) { - // This method and the one below are not inlined because - // using the decimal type results in quite a bit of code. - if ((ulong)Math.Abs((decimal)value - target) <= delta) + ulong difference; + + if (value >= target) + { + difference = (ulong)(value - target); + } + else + { + difference = (ulong)(target - value); + } + + if (difference <= delta) { return; } @@ -90,10 +110,21 @@ public static void IsCloseTo(long value, long target, ulong delta, string name) /// The maximum distance to allow between and . /// The name of the input parameter being tested. /// Thrown if ( - ) <= . - [MethodImpl(MethodImplOptions.NoInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsNotCloseTo(long value, long target, ulong delta, string name) { - if ((ulong)Math.Abs((decimal)value - target) > delta) + ulong difference; + + if (value >= target) + { + difference = (ulong)(value - target); + } + else + { + difference = (ulong)(target - value); + } + + if (difference > delta) { return; } From 6c8985f39185028a0993ea4f007d725f847d41ba Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 Nov 2020 15:44:15 +0100 Subject: [PATCH 06/12] Added Guard.IsCloseTo overloads for nint type --- .../Diagnostics/Guard.Comparable.Numeric.cs | 60 +++++++++++++++++++ .../ThrowHelper.Guard.Comparable.Numeric.cs | 20 +++++++ 2 files changed, 80 insertions(+) diff --git a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs index 302e255fa29..fb0e5aa18d3 100644 --- a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs @@ -207,5 +207,65 @@ public static void IsNotCloseTo(double value, double target, double delta, strin ThrowHelper.ThrowArgumentExceptionForIsNotCloseTo(value, target, delta, name); } + + /// + /// Asserts that the input value must be within a given distance from a specified value. + /// + /// The input value to test. + /// The target value to test for. + /// The maximum distance to allow between and . + /// The name of the input parameter being tested. + /// Thrown if ( - ) > . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsCloseTo(nint value, nint target, nuint delta, string name) + { + nuint difference; + + if (value >= target) + { + difference = (nuint)(value - target); + } + else + { + difference = (nuint)(target - value); + } + + if (difference <= delta) + { + return; + } + + ThrowHelper.ThrowArgumentExceptionForIsCloseTo(value, target, delta, name); + } + + /// + /// Asserts that the input value must not be within a given distance from a specified value. + /// + /// The input value to test. + /// The target value to test for. + /// The maximum distance to allow between and . + /// The name of the input parameter being tested. + /// Thrown if ( - ) <= . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotCloseTo(nint value, nint target, nuint delta, string name) + { + nuint difference; + + if (value >= target) + { + difference = (nuint)(value - target); + } + else + { + difference = (nuint)(target - value); + } + + if (difference > delta) + { + return; + } + + ThrowHelper.ThrowArgumentExceptionForIsNotCloseTo(value, target, delta, name); + } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs index 5afc5a1354d..7943e464c44 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs @@ -93,5 +93,25 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(double value, double { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsCloseTo(nint value, nint target, nuint delta, string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(nint).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsNotCloseTo(nint value, nint target, nuint delta, string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(nint).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); + } } } From bfa1ebdf4d9403ffdb108524913e751d8550e6e6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 29 Nov 2020 13:51:43 +0100 Subject: [PATCH 07/12] Improved Guard APIs codegen --- .../Generated/ThrowHelper.Collection.g.cs | 265 ++++++------------ .../Generated/ThrowHelper.Collection.tt | 34 +-- .../ThrowHelper.Guard.Collection.Generic.cs | 10 +- .../ThrowHelper.Guard.Comparable.Generic.cs | 46 +-- .../ThrowHelper.Guard.Comparable.Numeric.cs | 31 +- .../Internals/ThrowHelper.Guard.IO.cs | 13 +- .../Internals/ThrowHelper.Guard.String.cs | 55 ++-- .../Internals/ThrowHelper.Guard.Tasks.cs | 31 +- .../Internals/ThrowHelper.Guard.cs | 52 ++-- 9 files changed, 176 insertions(+), 361 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs index e75e6c5081d..74a2a5b1f3e 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs @@ -8,7 +8,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; namespace Microsoft.Toolkit.Diagnostics @@ -21,881 +20,793 @@ public static partial class ThrowHelper /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(Span span, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, Span destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span source, Span destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Span span, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan span, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan source, Span destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan source, Span destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(Memory memory, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, Memory destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory source, Memory destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory source, Memory destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory source, Memory destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must be empty, had a size of {array.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must be empty, had a size of {array.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {size}, had a size of {array.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {size}, had a size of {array.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size not equal to {size}, had a size of {array.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size not equal to {size}, had a size of {array.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {array.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {array.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {array.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {array.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than {size}, had a size of {array.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than {size}, had a size of {array.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] array, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {size}, had a size of {array.Length.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {size}, had a size of {array.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] source, T[] destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {array.Length.ToAssertString()} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {array.Length.ToAssertString()} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {array.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {array.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(List list, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must be empty, had a size of {list.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must be empty, had a size of {list.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {size}, had a size of {list.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {size}, had a size of {list.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size not equal to {size}, had a size of {list.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size not equal to {size}, had a size of {list.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {list.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {list.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {list.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {list.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(List list, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than {size}, had a size of {list.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than {size}, had a size of {list.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List list, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {size}, had a size of {list.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {size}, had a size of {list.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(List source, List destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List source, List destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, List list, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {list.Count.ToAssertString()} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {list.Count.ToAssertString()} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {list.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {list.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(ICollection collection, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(ICollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection source, ICollection destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection source, ICollection destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection collection, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection source, ICollection destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection source, ICollection destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt index 1a58e50ba03..21e74d7ce18 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; namespace Microsoft.Toolkit.Diagnostics @@ -22,111 +21,100 @@ GenerateTextForItems(EnumerableTypes, item => /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(<#=item.Type#> <#=item.Name#>, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(<#=item.Type#> <#=item.Name#>, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}", name); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); } /// /// Throws an when (or an overload) fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); } <# }); diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs index a3bf9ed0cc5..7a9770d6bb4 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; namespace Microsoft.Toolkit.Diagnostics @@ -19,11 +18,10 @@ public static partial class ThrowHelper /// /// The item of items in the input instance. /// This method is needed because can't be used as a generic type parameter. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must not be empty"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must not be empty", name); } /// @@ -31,22 +29,20 @@ internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) /// /// The item of items in the input instance. /// This method is needed because can't be used as a generic type parameter. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty", name); } /// /// Throws an when (or an overload) fails. /// /// The item of items in the input collection. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotEmpty(string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty", name); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs index 40d0cdad741..42b38a6c2ff 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; namespace Microsoft.Toolkit.Diagnostics @@ -18,168 +17,153 @@ public static partial class ThrowHelper /// Throws an when fails. /// /// The type of value type being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsDefault(T value, string name) where T : struct { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the default value {default(T).ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the default value {default(T).ToAssertString()}, was {value.ToAssertString()}", name); } /// /// Throws an when fails. /// /// The type of value type being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotDefault(string name) where T : struct { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the default value {default(T).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the default value {default(T).ToAssertString()}", name); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be equal to {target.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be equal to {target.ToAssertString()}, was {value.ToAssertString()}", name); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be equal to {target.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be equal to {target.ToAssertString()}, was {value.ToAssertString()}", name); } /// /// Throws an when fails. /// /// The type of input values being compared. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForBitwiseEqualTo(T value, T target, string name) where T : unmanaged { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>", name); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) { - ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}"); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) { - ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}"); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// /// Throws an when fails. /// /// The type of values being tested. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs index 7943e464c44..fcba1c48b86 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; namespace Microsoft.Toolkit.Diagnostics @@ -17,101 +16,91 @@ public static partial class ThrowHelper /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCloseTo(nint value, nint target, nuint delta, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(nint).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(nint).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCloseTo(nint value, nint target, nuint delta, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(nint).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(nint).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs index c6ddc4b24c1..622afdd21f2 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs @@ -5,7 +5,6 @@ using System; using System.Diagnostics.CodeAnalysis; using System.IO; -using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; namespace Microsoft.Toolkit.Diagnostics @@ -18,41 +17,37 @@ public static partial class ThrowHelper /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForCanRead(Stream stream, string name) { - ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support reading"); + throw new ArgumentException($"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support reading", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) { - ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support writing"); + throw new ArgumentException($"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support writing", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) { - ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support seeking"); + throw new ArgumentException($"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support seeking", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) { - ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) must be at position {0.ToAssertString()}, was at {stream.Position.ToAssertString()}"); + throw new ArgumentException($"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) must be at position {0.ToAssertString()}, was at {stream.Position.ToAssertString()}", name); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs index 84433f7c5c1..2896cc0416e 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; namespace Microsoft.Toolkit.Diagnostics { @@ -16,181 +15,163 @@ public static partial class ThrowHelper /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or empty, was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must be null or empty, was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be null or empty, was {(text is null ? "null" : "empty")}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must not be null or empty, was {(text is null ? "null" : "empty")}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNullOrWhiteSpace(string? text, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or whitespace, was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must be null or whitespace, was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotNullOrWhiteSpace(string? text, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be null or whitespace, was {(text is null ? "null" : "whitespace")}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must not be null or whitespace, was {(text is null ? "null" : "whitespace")}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(string text, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be empty, was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must be empty, was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be empty"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must not be empty", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsWhiteSpace(string text, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be whitespace, was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must be whitespace, was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotWhiteSpace(string text, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be whitespace, was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must not be whitespace, was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must have a size equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not have a size equal to {size}, was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must not have a size equal to {size}, was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size over {size}, had a size of {text.Length} and was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must have a size over {size}, had a size of {text.Length} and was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size of at least {size}, had a size of {text.Length} and was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must have a size of at least {size}, had a size of {text.Length} and was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size less than {size}, had a size of {text.Length} and was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must have a size less than {size}, had a size of {text.Length} and was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} (string) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} (string) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name) { - ThrowArgumentException(name, $"The source {name.ToAssertString()} (string) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + throw new ArgumentException($"The source {name.ToAssertString()} (string) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {text.Length.ToAssertString()} to be a valid index for the target string, was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {text.Length.ToAssertString()} to be a valid index for the target string, was {index.ToAssertString()}"); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) { - ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {text.Length.ToAssertString()} to be an invalid index for the target string, was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {text.Length.ToAssertString()} to be an invalid index for the target string, was {index.ToAssertString()}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs index 174d88c6a60..fa7a090e876 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; using System.Threading.Tasks; using Microsoft.Toolkit.Extensions; @@ -18,101 +17,91 @@ public static partial class ThrowHelper /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCompleted(Task task, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed, had status {task.Status.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed, had status {task.Status.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed, had status {task.Status.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed, had status {task.Status.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed successfully, had status {task.Status.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed successfully, had status {task.Status.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {task.Status.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {task.Status.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsFaulted(Task task, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be faulted, had status {task.Status.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be faulted, had status {task.Status.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be faulted, had status {task.Status.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be faulted, had status {task.Status.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCanceled(Task task, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be canceled, had status {task.Status.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be canceled, had status {task.Status.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be canceled, had status {task.Status.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be canceled, had status {task.Status.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must have status {status}, had status {task.Status.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must have status {status}, had status {task.Status.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not have status {status.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not have status {status.ToAssertString()}", name); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs index 4228d086a64..d073bb123ea 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs @@ -5,7 +5,6 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; -using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; namespace Microsoft.Toolkit.Diagnostics @@ -35,183 +34,166 @@ private static string ToAssertString(this object? obj) /// Throws an when (where is ) fails. /// /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNull(T value, string name) where T : class { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be null, was {value.ToAssertString()} ({value.GetType().ToTypeString()})"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be null, was {value.ToAssertString()} ({value.GetType().ToTypeString()})", name); } /// /// Throws an when (where is ) fails. /// /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNull(T? value, string name) where T : struct { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T?).ToTypeString()}) must be null, was {value.ToAssertString()} ({typeof(T).ToTypeString()})"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T?).ToTypeString()}) must be null, was {value.ToAssertString()} ({typeof(T).ToTypeString()})", name); } /// /// Throws an when fails. /// /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentNullExceptionForIsNotNull(string name) { - ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)"); + throw new ArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)"); } /// /// Throws an when fails. /// /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsOfType(object value, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// /// Throws an when fails. /// /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotOfType(object value, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// /// Throws an when fails. /// /// The type being checked against. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// /// Throws an when fails. /// /// The type being checked against. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// /// Throws an when fails. /// /// The type of input value being compared. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) where T : class { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the same instance as the target object"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the same instance as the target object", name); } /// /// Throws an when fails. /// /// The type of input value being compared. - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) where T : class { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the same instance as the target object"); + throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the same instance as the target object", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsTrue(string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must be true, was false", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsTrue(string name, string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsFalse(string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must be false, was true", name); } /// /// Throws an when fails. /// - [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] internal static void ThrowArgumentExceptionForIsFalse(string name, string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}"); + throw new ArgumentException($"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}", name); } } } From 525be0c5f0875a94ad5570cc2c894f8f8ad42660 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 30 Nov 2020 19:49:36 +0100 Subject: [PATCH 08/12] Renamed files to match new class structure --- ...lection.Generic.cs => Guard.Collection.Generic.ThrowHelper.cs} | 0 ...parable.Generic.cs => Guard.Comparable.Generic.ThrowHelper.cs} | 0 ...parable.Numeric.cs => Guard.Comparable.Numeric.ThrowHelper.cs} | 0 .../{ThrowHelper.Guard.IO.cs => Guard.IO.ThrowHelper.cs} | 0 .../{ThrowHelper.Guard.String.cs => Guard.String.ThrowHelper.cs} | 0 .../{ThrowHelper.Guard.Tasks.cs => Guard.Tasks.ThrowHelper.cs} | 0 .../Internals/{ThrowHelper.Guard.cs => Guard.ThrowHelper.cs} | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename Microsoft.Toolkit/Diagnostics/Internals/{ThrowHelper.Guard.Collection.Generic.cs => Guard.Collection.Generic.ThrowHelper.cs} (100%) rename Microsoft.Toolkit/Diagnostics/Internals/{ThrowHelper.Guard.Comparable.Generic.cs => Guard.Comparable.Generic.ThrowHelper.cs} (100%) rename Microsoft.Toolkit/Diagnostics/Internals/{ThrowHelper.Guard.Comparable.Numeric.cs => Guard.Comparable.Numeric.ThrowHelper.cs} (100%) rename Microsoft.Toolkit/Diagnostics/Internals/{ThrowHelper.Guard.IO.cs => Guard.IO.ThrowHelper.cs} (100%) rename Microsoft.Toolkit/Diagnostics/Internals/{ThrowHelper.Guard.String.cs => Guard.String.ThrowHelper.cs} (100%) rename Microsoft.Toolkit/Diagnostics/Internals/{ThrowHelper.Guard.Tasks.cs => Guard.Tasks.ThrowHelper.cs} (100%) rename Microsoft.Toolkit/Diagnostics/Internals/{ThrowHelper.Guard.cs => Guard.ThrowHelper.cs} (100%) diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Collection.Generic.ThrowHelper.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs rename to Microsoft.Toolkit/Diagnostics/Internals/Guard.Collection.Generic.ThrowHelper.cs diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Generic.ThrowHelper.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs rename to Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Generic.ThrowHelper.cs diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Numeric.ThrowHelper.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs rename to Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Numeric.ThrowHelper.cs diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.IO.ThrowHelper.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs rename to Microsoft.Toolkit/Diagnostics/Internals/Guard.IO.ThrowHelper.cs diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.String.ThrowHelper.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs rename to Microsoft.Toolkit/Diagnostics/Internals/Guard.String.ThrowHelper.cs diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Tasks.ThrowHelper.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs rename to Microsoft.Toolkit/Diagnostics/Internals/Guard.Tasks.ThrowHelper.cs diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.ThrowHelper.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs rename to Microsoft.Toolkit/Diagnostics/Internals/Guard.ThrowHelper.cs From e585856c85f24185560675a0409dbe9067fdd9c3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 30 Nov 2020 20:14:09 +0100 Subject: [PATCH 09/12] Minor code refactoring for new class structure --- .../Generated/ThrowHelper.Collection.g.cs | 176 +++++++++--------- .../Generated/ThrowHelper.Collection.tt | 22 +-- .../Guard.Collection.Generic.ThrowHelper.cs | 6 +- .../Guard.Comparable.Generic.ThrowHelper.cs | 30 +-- .../Guard.Comparable.Numeric.ThrowHelper.cs | 20 +- .../Internals/Guard.IO.ThrowHelper.cs | 8 +- .../Internals/Guard.String.ThrowHelper.cs | 36 ++-- .../Internals/Guard.Tasks.ThrowHelper.cs | 20 +- .../Internals/Guard.ThrowHelper.cs | 36 ++-- 9 files changed, 177 insertions(+), 177 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs index 74a2a5b1f3e..38a740c2092 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs @@ -23,7 +23,7 @@ public static partial class ThrowHelper [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(Span span, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must be empty, had a size of {AssertString(span.Length)}", name); } /// @@ -32,7 +32,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(Span span, string na [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -41,7 +41,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, in [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -50,7 +50,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -59,7 +59,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -68,7 +68,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Spa [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -77,7 +77,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(Span span, i [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -86,7 +86,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span(Span source, Span destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -95,7 +95,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span source, Span destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -104,7 +104,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span(int index, Span span, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(span.Length)} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {AssertString(index)}"); } /// @@ -113,7 +113,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(span.Length)} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {AssertString(index)}"); } /// @@ -122,7 +122,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must be empty, had a size of {AssertString(span.Length)}", name); } /// @@ -131,7 +131,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, s [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -140,7 +140,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -149,7 +149,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan< [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -158,7 +158,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -167,7 +167,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Rea [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -176,7 +176,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan span, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(span.Length)}", name); } /// @@ -185,7 +185,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan source, Span destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -194,7 +194,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan source, Span destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -203,7 +203,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(span.Length)} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {AssertString(index)}"); } /// @@ -212,7 +212,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(span.Length)} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {AssertString(index)}"); } /// @@ -221,7 +221,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(Memory memory, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must be empty, had a size of {AssertString(memory.Length)}", name); } /// @@ -230,7 +230,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(Memory memory, strin [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -239,7 +239,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -248,7 +248,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory mem [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -257,7 +257,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory me [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -266,7 +266,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Mem [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -275,7 +275,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(Memory memor [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -284,7 +284,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, Memory destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -293,7 +293,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory source, Memory destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -302,7 +302,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(memory.Length)} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {AssertString(index)}"); } /// @@ -311,7 +311,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(memory.Length)} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {AssertString(index)}"); } /// @@ -320,7 +320,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must be empty, had a size of {AssertString(memory.Length)}", name); } /// @@ -329,7 +329,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memor [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -338,7 +338,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory(ReadOnlyMemory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -347,7 +347,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemor [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -356,7 +356,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemo [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -365,7 +365,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Rea [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -374,7 +374,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory< [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(memory.Length)}", name); } /// @@ -383,7 +383,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory source, Memory destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -392,7 +392,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory(ReadOnlyMemory source, Memory destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -401,7 +401,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(memory.Length)} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {AssertString(index)}"); } /// @@ -410,7 +410,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(memory.Length)} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {AssertString(index)}"); } /// @@ -419,7 +419,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must be empty, had a size of {array.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must be empty, had a size of {AssertString(array.Length)}", name); } /// @@ -428,7 +428,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {size}, had a size of {array.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(array.Length)}", name); } /// @@ -437,7 +437,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int s [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size not equal to {size}, had a size of {array.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(array.Length)}", name); } /// @@ -446,7 +446,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, in [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {array.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {AssertString(array.Length)}", name); } /// @@ -455,7 +455,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, i [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {array.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(array.Length)}", name); } /// @@ -464,7 +464,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than {size}, had a size of {array.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(array.Length)}", name); } /// @@ -473,7 +473,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] array, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {size}, had a size of {array.Length.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(array.Length)}", name); } /// @@ -482,7 +482,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] ar [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -491,7 +491,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] source, T[] destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -500,7 +500,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] so [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {array.Length.ToAssertString()} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(array.Length)} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {AssertString(index)}"); } /// @@ -509,7 +509,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {array.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(array.Length)} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {AssertString(index)}"); } /// @@ -518,7 +518,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(List list, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must be empty, had a size of {list.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must be empty, had a size of {AssertString(list.Count)}", name); } /// @@ -527,7 +527,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(List list, string na [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {size}, had a size of {list.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(list.Count)}", name); } /// @@ -536,7 +536,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(List list, in [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size not equal to {size}, had a size of {list.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(list.Count)}", name); } /// @@ -545,7 +545,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {list.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {AssertString(list.Count)}", name); } /// @@ -554,7 +554,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(List list [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {list.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(list.Count)}", name); } /// @@ -563,7 +563,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Lis [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(List list, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than {size}, had a size of {list.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(list.Count)}", name); } /// @@ -572,7 +572,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(List list, i [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List list, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {size}, had a size of {list.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(list.Count)}", name); } /// @@ -581,7 +581,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List(List source, List destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); } /// @@ -590,7 +590,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(List source, [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List source, List destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); } /// @@ -599,7 +599,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List(int index, List list, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {list.Count.ToAssertString()} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(list.Count)} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {AssertString(index)}"); } /// @@ -608,7 +608,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {list.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(list.Count)} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {AssertString(index)}"); } /// @@ -617,7 +617,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(ICollection collection, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must be empty, had a size of {AssertString(collection.Count)}", name); } /// @@ -626,7 +626,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(ICollection collecti [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -635,7 +635,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection c [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -644,7 +644,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection(ICollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -653,7 +653,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection< [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -662,7 +662,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICo [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(ICollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -671,7 +671,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(ICollection [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -680,7 +680,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IColle [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection source, ICollection destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); } /// @@ -689,7 +689,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection s [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection source, ICollection destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); } /// @@ -698,7 +698,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IColle [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(collection.Count)} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {AssertString(index)}"); } /// @@ -707,7 +707,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(collection.Count)} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {AssertString(index)}"); } /// @@ -716,7 +716,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection collection, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must be empty, had a size of {AssertString(collection.Count)}", name); } /// @@ -725,7 +725,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -734,7 +734,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollect [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -743,7 +743,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyColl [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -752,7 +752,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCol [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -761,7 +761,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IRe [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -770,7 +770,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollec [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(collection.Count)}", name); } /// @@ -779,7 +779,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadO [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection source, ICollection destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); } /// @@ -788,7 +788,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollect [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection source, ICollection destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); } /// @@ -797,7 +797,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadO [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(collection.Count)} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {AssertString(index)}"); } /// @@ -806,7 +806,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(collection.Count)} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {AssertString(index)}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt index 21e74d7ce18..e6747a9ddd3 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt @@ -24,7 +24,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(<#=item.Type#> <#=item.Name#>, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); } /// @@ -33,7 +33,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); } /// @@ -42,7 +42,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); } /// @@ -51,7 +51,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); } /// @@ -60,7 +60,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); } /// @@ -69,7 +69,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(<#=item.Type#> <#=item.Name#>, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); } /// @@ -78,7 +78,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); } /// @@ -87,7 +87,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}", name); } /// @@ -96,7 +96,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}", name); } /// @@ -105,7 +105,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}"); } /// @@ -114,7 +114,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}"); } <# }); diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Collection.Generic.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Collection.Generic.ThrowHelper.cs index 7a9770d6bb4..e6a228b0725 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Collection.Generic.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Collection.Generic.ThrowHelper.cs @@ -21,7 +21,7 @@ public static partial class ThrowHelper [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must not be empty", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must not be empty", name); } /// @@ -32,7 +32,7 @@ internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty", name); } /// @@ -42,7 +42,7 @@ internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(stri [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotEmpty(string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be empty", name); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Generic.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Generic.ThrowHelper.cs index 42b38a6c2ff..c7f215ecc60 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Generic.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Generic.ThrowHelper.cs @@ -21,7 +21,7 @@ public static partial class ThrowHelper internal static void ThrowArgumentExceptionForIsDefault(T value, string name) where T : struct { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the default value {default(T).ToAssertString()}, was {value.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be the default value {AssertString(default(T))}, was {AssertString(value)}", name); } /// @@ -32,7 +32,7 @@ internal static void ThrowArgumentExceptionForIsDefault(T value, string name) internal static void ThrowArgumentExceptionForIsNotDefault(string name) where T : struct { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the default value {default(T).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be the default value {AssertString(default(T))}", name); } /// @@ -42,7 +42,7 @@ internal static void ThrowArgumentExceptionForIsNotDefault(string name) [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be equal to {target.ToAssertString()}, was {value.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be equal to {AssertString(target)}, was {AssertString(value)}", name); } /// @@ -52,7 +52,7 @@ internal static void ThrowArgumentExceptionForIsEqualTo(T value, T target, st [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be equal to {target.ToAssertString()}, was {value.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be equal to {AssertString(target)}, was {AssertString(value)}", name); } /// @@ -63,7 +63,7 @@ internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, internal static void ThrowArgumentExceptionForBitwiseEqualTo(T value, T target, string name) where T : unmanaged { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>", name); } /// @@ -73,7 +73,7 @@ internal static void ThrowArgumentExceptionForBitwiseEqualTo(T value, T targe [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be less than {AssertString(maximum)}, was {AssertString(value)}"); } /// @@ -83,7 +83,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be less than or equal to {AssertString(maximum)}, was {AssertString(value)}"); } /// @@ -93,7 +93,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be greater than {AssertString(minimum)}, was {AssertString(value)}"); } /// @@ -103,7 +103,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be greater than or equal to {AssertString(minimum)}, was {AssertString(value)}"); } /// @@ -113,7 +113,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, T maximum, string name) { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be in the range given by {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); } /// @@ -123,7 +123,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be in the range given by {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); } /// @@ -133,7 +133,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be between {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); } /// @@ -143,7 +143,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be between {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); } /// @@ -153,7 +153,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be between or equal to {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); } /// @@ -163,7 +163,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be between or equal to {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Numeric.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Numeric.ThrowHelper.cs index fcba1c48b86..2fe8cdda6bb 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Numeric.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Numeric.ThrowHelper.cs @@ -19,7 +19,7 @@ public static partial class ThrowHelper [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}", name); } /// @@ -28,7 +28,7 @@ internal static void ThrowArgumentExceptionForIsCloseTo(int value, int target, u [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}", name); } /// @@ -37,7 +37,7 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}", name); } /// @@ -46,7 +46,7 @@ internal static void ThrowArgumentExceptionForIsCloseTo(long value, long target, [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}", name); } /// @@ -55,7 +55,7 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(long value, long targ [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); } /// @@ -64,7 +64,7 @@ internal static void ThrowArgumentExceptionForIsCloseTo(float value, float targe [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); } /// @@ -73,7 +73,7 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(float value, float ta [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); } /// @@ -82,7 +82,7 @@ internal static void ThrowArgumentExceptionForIsCloseTo(double value, double tar [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); } /// @@ -91,7 +91,7 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(double value, double [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCloseTo(nint value, nint target, nuint delta, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(nint).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); } /// @@ -100,7 +100,7 @@ internal static void ThrowArgumentExceptionForIsCloseTo(nint value, nint target, [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCloseTo(nint value, nint target, nuint delta, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(nint).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.IO.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.IO.ThrowHelper.cs index 622afdd21f2..c25a04f8588 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.IO.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.IO.ThrowHelper.cs @@ -20,7 +20,7 @@ public static partial class ThrowHelper [DoesNotReturn] internal static void ThrowArgumentExceptionForCanRead(Stream stream, string name) { - throw new ArgumentException($"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support reading", name); + throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support reading", name); } /// @@ -29,7 +29,7 @@ internal static void ThrowArgumentExceptionForCanRead(Stream stream, string name [DoesNotReturn] internal static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) { - throw new ArgumentException($"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support writing", name); + throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support writing", name); } /// @@ -38,7 +38,7 @@ internal static void ThrowArgumentExceptionForCanWrite(Stream stream, string nam [DoesNotReturn] internal static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) { - throw new ArgumentException($"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support seeking", name); + throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support seeking", name); } /// @@ -47,7 +47,7 @@ internal static void ThrowArgumentExceptionForCanSeek(Stream stream, string name [DoesNotReturn] internal static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) { - throw new ArgumentException($"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) must be at position {0.ToAssertString()}, was at {stream.Position.ToAssertString()}", name); + throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) must be at position {AssertString(0)}, was at {AssertString(stream.Position)}", name); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.String.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.String.ThrowHelper.cs index 2896cc0416e..49bfa4eba86 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.String.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.String.ThrowHelper.cs @@ -18,7 +18,7 @@ public static partial class ThrowHelper [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must be null or empty, was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must be null or empty, was {AssertString(text)}", name); } /// @@ -27,7 +27,7 @@ internal static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must not be null or empty, was {(text is null ? "null" : "empty")}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be null or empty, was {(text is null ? "null" : "empty")}", name); } /// @@ -36,7 +36,7 @@ internal static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, str [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNullOrWhiteSpace(string? text, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must be null or whitespace, was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must be null or whitespace, was {AssertString(text)}", name); } /// @@ -45,7 +45,7 @@ internal static void ThrowArgumentExceptionForIsNullOrWhiteSpace(string? text, s [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotNullOrWhiteSpace(string? text, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must not be null or whitespace, was {(text is null ? "null" : "whitespace")}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be null or whitespace, was {(text is null ? "null" : "whitespace")}", name); } /// @@ -54,7 +54,7 @@ internal static void ThrowArgumentExceptionForIsNotNullOrWhiteSpace(string? text [DoesNotReturn] internal static void ThrowArgumentExceptionForIsEmpty(string text, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must be empty, was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must be empty, was {AssertString(text)}", name); } /// @@ -63,7 +63,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(string text, string name) [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must not be empty", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be empty", name); } /// @@ -72,7 +72,7 @@ internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string nam [DoesNotReturn] internal static void ThrowArgumentExceptionForIsWhiteSpace(string text, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must be whitespace, was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must be whitespace, was {AssertString(text)}", name); } /// @@ -81,7 +81,7 @@ internal static void ThrowArgumentExceptionForIsWhiteSpace(string text, string n [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotWhiteSpace(string text, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must not be whitespace, was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be whitespace, was {AssertString(text)}", name); } /// @@ -90,7 +90,7 @@ internal static void ThrowArgumentExceptionForIsNotWhiteSpace(string text, strin [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must have a size equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size equal to {size}, had a size of {text.Length} and was {AssertString(text)}", name); } /// @@ -99,7 +99,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int si [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must not have a size equal to {size}, was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must not have a size equal to {size}, was {AssertString(text)}", name); } /// @@ -108,7 +108,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must have a size over {size}, had a size of {text.Length} and was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size over {size}, had a size of {text.Length} and was {AssertString(text)}", name); } /// @@ -117,7 +117,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, in [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must have a size of at least {size}, had a size of {text.Length} and was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size of at least {size}, had a size of {text.Length} and was {AssertString(text)}", name); } /// @@ -126,7 +126,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must have a size less than {size}, had a size of {text.Length} and was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size less than {size}, had a size of {text.Length} and was {AssertString(text)}", name); } /// @@ -135,7 +135,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(string text, int s [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {AssertString(text)}", name); } /// @@ -144,7 +144,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string te [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} (string) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} (string) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -153,7 +153,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(string source, stri [DoesNotReturn] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name) { - throw new ArgumentException($"The source {name.ToAssertString()} (string) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}", name); + throw new ArgumentException($"The source {AssertString(name)} (string) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); } /// @@ -162,7 +162,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string so [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {text.Length.ToAssertString()} to be a valid index for the target string, was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(text.Length)} to be a valid index for the target string, was {AssertString(index)}"); } /// @@ -171,7 +171,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {text.Length.ToAssertString()} to be an invalid index for the target string, was {index.ToAssertString()}"); + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(text.Length)} to be an invalid index for the target string, was {AssertString(index)}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Tasks.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Tasks.ThrowHelper.cs index fa7a090e876..0f3577ca08b 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Tasks.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Tasks.ThrowHelper.cs @@ -20,7 +20,7 @@ public static partial class ThrowHelper [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCompleted(Task task, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed, had status {task.Status.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be completed, had status {AssertString(task.Status)}", name); } /// @@ -29,7 +29,7 @@ internal static void ThrowArgumentExceptionForIsCompleted(Task task, string name [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed, had status {task.Status.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be completed, had status {AssertString(task.Status)}", name); } /// @@ -38,7 +38,7 @@ internal static void ThrowArgumentExceptionForIsNotCompleted(Task task, string n [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed successfully, had status {task.Status.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be completed successfully, had status {AssertString(task.Status)}", name); } /// @@ -47,7 +47,7 @@ internal static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {task.Status.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {AssertString(task.Status)}", name); } /// @@ -56,7 +56,7 @@ internal static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task ta [DoesNotReturn] internal static void ThrowArgumentExceptionForIsFaulted(Task task, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be faulted, had status {task.Status.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be faulted, had status {AssertString(task.Status)}", name); } /// @@ -65,7 +65,7 @@ internal static void ThrowArgumentExceptionForIsFaulted(Task task, string name) [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be faulted, had status {task.Status.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be faulted, had status {AssertString(task.Status)}", name); } /// @@ -74,7 +74,7 @@ internal static void ThrowArgumentExceptionForIsNotFaulted(Task task, string nam [DoesNotReturn] internal static void ThrowArgumentExceptionForIsCanceled(Task task, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be canceled, had status {task.Status.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be canceled, had status {AssertString(task.Status)}", name); } /// @@ -83,7 +83,7 @@ internal static void ThrowArgumentExceptionForIsCanceled(Task task, string name) [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be canceled, had status {task.Status.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be canceled, had status {AssertString(task.Status)}", name); } /// @@ -92,7 +92,7 @@ internal static void ThrowArgumentExceptionForIsNotCanceled(Task task, string na [DoesNotReturn] internal static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must have status {status}, had status {task.Status.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must have status {status}, had status {AssertString(task.Status)}", name); } /// @@ -101,7 +101,7 @@ internal static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskSt [DoesNotReturn] internal static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not have status {status.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not have status {AssertString(status)}", name); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.ThrowHelper.cs index d073bb123ea..452319425df 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.ThrowHelper.cs @@ -20,7 +20,7 @@ public static partial class ThrowHelper /// The input to format. /// A formatted representation of to display in error messages. [Pure] - private static string ToAssertString(this object? obj) + private static string AssertString(object? obj) { return obj switch { @@ -38,7 +38,7 @@ private static string ToAssertString(this object? obj) internal static void ThrowArgumentExceptionForIsNull(T value, string name) where T : class { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be null, was {value.ToAssertString()} ({value.GetType().ToTypeString()})", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be null, was {AssertString(value)} ({value.GetType().ToTypeString()})", name); } /// @@ -49,7 +49,7 @@ internal static void ThrowArgumentExceptionForIsNull(T value, string name) internal static void ThrowArgumentExceptionForIsNull(T? value, string name) where T : struct { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T?).ToTypeString()}) must be null, was {value.ToAssertString()} ({typeof(T).ToTypeString()})", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T?).ToTypeString()}) must be null, was {AssertString(value)} ({typeof(T).ToTypeString()})", name); } /// @@ -59,7 +59,7 @@ internal static void ThrowArgumentExceptionForIsNull(T? value, string name) [DoesNotReturn] internal static void ThrowArgumentNullExceptionForIsNotNull(string name) { - throw new ArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)"); + throw new ArgumentNullException(name, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be not null)"); } /// @@ -69,7 +69,7 @@ internal static void ThrowArgumentNullExceptionForIsNotNull(string name) [DoesNotReturn] internal static void ThrowArgumentExceptionForIsOfType(object value, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// @@ -79,7 +79,7 @@ internal static void ThrowArgumentExceptionForIsOfType(object value, string n [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotOfType(object value, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// @@ -88,7 +88,7 @@ internal static void ThrowArgumentExceptionForIsNotOfType(object value, strin [DoesNotReturn] internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// @@ -97,7 +97,7 @@ internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// @@ -107,7 +107,7 @@ internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type typ [DoesNotReturn] internal static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// @@ -117,7 +117,7 @@ internal static void ThrowArgumentExceptionForIsAssignableToType(object value [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// @@ -126,7 +126,7 @@ internal static void ThrowArgumentExceptionForIsNotAssignableToType(object va [DoesNotReturn] internal static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// @@ -135,7 +135,7 @@ internal static void ThrowArgumentExceptionForIsAssignableToType(object value, T [DoesNotReturn] internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); } /// @@ -146,7 +146,7 @@ internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) where T : class { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the same instance as the target object", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be the same instance as the target object", name); } /// @@ -157,7 +157,7 @@ internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) where T : class { - throw new ArgumentException($"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the same instance as the target object", name); + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be the same instance as the target object", name); } /// @@ -166,7 +166,7 @@ internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string na [DoesNotReturn] internal static void ThrowArgumentExceptionForIsTrue(string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must be true, was false", name); + throw new ArgumentException($"Parameter {AssertString(name)} must be true, was false", name); } /// @@ -175,7 +175,7 @@ internal static void ThrowArgumentExceptionForIsTrue(string name) [DoesNotReturn] internal static void ThrowArgumentExceptionForIsTrue(string name, string message) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} must be true, was false: {AssertString(message)}", name); } /// @@ -184,7 +184,7 @@ internal static void ThrowArgumentExceptionForIsTrue(string name, string message [DoesNotReturn] internal static void ThrowArgumentExceptionForIsFalse(string name) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must be false, was true", name); + throw new ArgumentException($"Parameter {AssertString(name)} must be false, was true", name); } /// @@ -193,7 +193,7 @@ internal static void ThrowArgumentExceptionForIsFalse(string name) [DoesNotReturn] internal static void ThrowArgumentExceptionForIsFalse(string name, string message) { - throw new ArgumentException($"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}", name); + throw new ArgumentException($"Parameter {AssertString(name)} must be false, was true: {AssertString(message)}", name); } } } From 4ef9074d08e329d6b5b70fa8a596fa6f65c467ef Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 30 Nov 2020 20:22:08 +0100 Subject: [PATCH 10/12] Decoupled Guard helpers from ThrowHelper class --- .../Generated/ThrowHelper.Collection.g.cs | 1588 +++++++++-------- .../Generated/ThrowHelper.Collection.tt | 186 +- .../Guard.Collection.Generic.ThrowHelper.cs | 60 +- .../Guard.Comparable.Generic.ThrowHelper.cs | 306 ++-- .../Guard.Comparable.Numeric.ThrowHelper.cs | 162 +- .../Internals/Guard.IO.ThrowHelper.cs | 66 +- .../Internals/Guard.String.ThrowHelper.cs | 328 ++-- .../Internals/Guard.Tasks.ThrowHelper.cs | 162 +- .../Internals/Guard.ThrowHelper.cs | 362 ++-- 9 files changed, 1637 insertions(+), 1583 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs index 38a740c2092..1499c68fccc 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs @@ -13,800 +13,806 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to efficiently throw exceptions. + /// Helper methods to verify conditions when running code. /// - public static partial class ThrowHelper + public static partial class Guard { /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEmpty(Span span, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must be empty, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, Span destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span source, Span destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Span span, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(span.Length)} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(span.Length)} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must be empty, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan span, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(span.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan source, Span destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan source, Span destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(span.Length)} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(span.Length)} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEmpty(Memory memory, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must be empty, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, Memory destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory source, Memory destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(memory.Length)} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(memory.Length)} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must be empty, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory memory, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(memory.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory source, Memory destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory source, Memory destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(memory.Length)} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(memory.Length)} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must be empty, had a size of {AssertString(array.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(array.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(array.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {AssertString(array.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(array.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(array.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] array, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(array.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] source, T[] destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(array.Length)} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(array.Length)} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEmpty(List list, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must be empty, had a size of {AssertString(list.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(list.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(list.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {AssertString(list.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(list.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThan(List list, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(list.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List list, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(list.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(List source, List destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List source, List destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, List list, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(list.Count)} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(list.Count)} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEmpty(ICollection collection, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must be empty, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThan(ICollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection source, ICollection destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection source, ICollection destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(collection.Count)} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(collection.Count)} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection collection, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must be empty, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection collection, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(collection.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection source, ICollection destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection source, ICollection destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(collection.Count)} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {AssertString(index)}"); - } - - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(collection.Count)} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {AssertString(index)}"); + /// Helper methods to efficiently throw exceptions. + /// + private static partial class ThrowHelper + { + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEmpty(Span span, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must be empty, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, Span destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span source, Span destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Span span, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(span.Length)} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(span.Length)} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must be empty, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan span, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(span.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan source, Span destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan source, Span destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(span.Length)} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(span.Length)} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEmpty(Memory memory, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must be empty, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, Memory destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory source, Memory destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(memory.Length)} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(memory.Length)} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must be empty, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory memory, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(memory.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory source, Memory destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory source, Memory destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(memory.Length)} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(memory.Length)} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must be empty, had a size of {AssertString(array.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(array.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(array.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {AssertString(array.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(array.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(array.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] array, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(array.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] source, T[] destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(array.Length)} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(array.Length)} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEmpty(List list, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must be empty, had a size of {AssertString(list.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(list.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(list.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {AssertString(list.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(list.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThan(List list, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(list.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List list, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(list.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(List source, List destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List source, List destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(List).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, List list, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(list.Count)} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(list.Count)} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEmpty(ICollection collection, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must be empty, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThan(ICollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection source, ICollection destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection source, ICollection destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(collection.Count)} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(collection.Count)} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection collection, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must be empty, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection collection, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(collection.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection source, ICollection destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection source, ICollection destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {AssertString(destination.Count)} (the destination), had a size of {AssertString(source.Count)}", name); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(collection.Count)} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {AssertString(index)}"); + } + + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(collection.Count)} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {AssertString(index)}"); + } } } } diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt index e6747a9ddd3..83e74189031 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt @@ -10,114 +10,120 @@ using Microsoft.Toolkit.Extensions; namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to efficiently throw exceptions. + /// Helper methods to verify conditions when running code. /// - public static partial class ThrowHelper + public static partial class Guard { + /// + /// Helper methods to efficiently throw exceptions. + /// + private static partial class ThrowHelper + { <# GenerateTextForItems(EnumerableTypes, item => { #> - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEmpty(<#=item.Type#> <#=item.Name#>, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEmpty(<#=item.Type#> <#=item.Name#>, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); + } - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); + } - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); + } - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); + } - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); + } - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThan(<#=item.Type#> <#=item.Name#>, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThan(<#=item.Type#> <#=item.Name#>, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); + } - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}", name); + } - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}", name); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}", name); + } - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}", name); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}", name); + } - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}"); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}"); + } - /// - /// Throws an when (or an overload) fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}"); - } + /// + /// Throws an when (or an overload) fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}"); + } <# }); #> + } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Collection.Generic.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Collection.Generic.ThrowHelper.cs index e6a228b0725..0353f63d25d 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Collection.Generic.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Collection.Generic.ThrowHelper.cs @@ -9,40 +9,46 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to efficiently throw exceptions. + /// Helper methods to verify conditions when running code. /// - public static partial class ThrowHelper + public static partial class Guard { /// - /// Throws an when fails. + /// Helper methods to efficiently throw exceptions. /// - /// The item of items in the input instance. - /// This method is needed because can't be used as a generic type parameter. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) + private static partial class ThrowHelper { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must not be empty", name); - } + /// + /// Throws an when fails. + /// + /// The item of items in the input instance. + /// This method is needed because can't be used as a generic type parameter. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must not be empty", name); + } - /// - /// Throws an when fails. - /// - /// The item of items in the input instance. - /// This method is needed because can't be used as a generic type parameter. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty", name); - } + /// + /// Throws an when fails. + /// + /// The item of items in the input instance. + /// This method is needed because can't be used as a generic type parameter. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty", name); + } - /// - /// Throws an when (or an overload) fails. - /// - /// The item of items in the input collection. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotEmpty(string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be empty", name); + /// + /// Throws an when (or an overload) fails. + /// + /// The item of items in the input collection. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotEmpty(string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be empty", name); + } } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Generic.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Generic.ThrowHelper.cs index c7f215ecc60..dd7cc5c2abc 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Generic.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Generic.ThrowHelper.cs @@ -9,161 +9,167 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to efficiently throw exceptions. + /// Helper methods to verify conditions when running code. /// - public static partial class ThrowHelper + public static partial class Guard { /// - /// Throws an when fails. + /// Helper methods to efficiently throw exceptions. /// - /// The type of value type being tested. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsDefault(T value, string name) - where T : struct + private static partial class ThrowHelper { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be the default value {AssertString(default(T))}, was {AssertString(value)}", name); - } - - /// - /// Throws an when fails. - /// - /// The type of value type being tested. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotDefault(string name) - where T : struct - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be the default value {AssertString(default(T))}", name); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be equal to {AssertString(target)}, was {AssertString(value)}", name); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be equal to {AssertString(target)}, was {AssertString(value)}", name); - } - - /// - /// Throws an when fails. - /// - /// The type of input values being compared. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForBitwiseEqualTo(T value, T target, string name) - where T : unmanaged - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>", name); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) - { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be less than {AssertString(maximum)}, was {AssertString(value)}"); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) - { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be less than or equal to {AssertString(maximum)}, was {AssertString(value)}"); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) - { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be greater than {AssertString(minimum)}, was {AssertString(value)}"); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) - { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be greater than or equal to {AssertString(minimum)}, was {AssertString(value)}"); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name) - { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be in the range given by {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) - { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be in the range given by {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) - { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be between {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) - { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be between {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) - { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be between or equal to {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); - } - - /// - /// Throws an when fails. - /// - /// The type of values being tested. - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) - { - throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be between or equal to {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); + /// + /// Throws an when fails. + /// + /// The type of value type being tested. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsDefault(T value, string name) + where T : struct + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be the default value {AssertString(default(T))}, was {AssertString(value)}", name); + } + + /// + /// Throws an when fails. + /// + /// The type of value type being tested. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotDefault(string name) + where T : struct + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be the default value {AssertString(default(T))}", name); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be equal to {AssertString(target)}, was {AssertString(value)}", name); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be equal to {AssertString(target)}, was {AssertString(value)}", name); + } + + /// + /// Throws an when fails. + /// + /// The type of input values being compared. + [DoesNotReturn] + public static void ThrowArgumentExceptionForBitwiseEqualTo(T value, T target, string name) + where T : unmanaged + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>", name); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) + { + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be less than {AssertString(maximum)}, was {AssertString(value)}"); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) + { + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be less than or equal to {AssertString(maximum)}, was {AssertString(value)}"); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) + { + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be greater than {AssertString(minimum)}, was {AssertString(value)}"); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) + { + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be greater than or equal to {AssertString(minimum)}, was {AssertString(value)}"); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name) + { + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be in the range given by {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) + { + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be in the range given by {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) + { + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be between {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) + { + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be between {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) + { + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be between or equal to {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); + } + + /// + /// Throws an when fails. + /// + /// The type of values being tested. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) + { + throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be between or equal to {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}"); + } } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Numeric.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Numeric.ThrowHelper.cs index 2fe8cdda6bb..98ea1cf68f4 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Numeric.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Comparable.Numeric.ThrowHelper.cs @@ -9,98 +9,104 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to efficiently throw exceptions. + /// Helper methods to verify conditions when running code. /// - public static partial class ThrowHelper + public static partial class Guard { /// - /// Throws an when fails. + /// Helper methods to efficiently throw exceptions. /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) + private static partial class ThrowHelper { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsCloseTo(nint value, nint target, nuint delta, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsCloseTo(nint value, nint target, nuint delta, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotCloseTo(nint value, nint target, nuint delta, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotCloseTo(nint value, nint target, nuint delta, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}", name); + } } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.IO.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.IO.ThrowHelper.cs index c25a04f8588..a51341c8305 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.IO.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.IO.ThrowHelper.cs @@ -10,44 +10,50 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to efficiently throw exceptions. + /// Helper methods to verify conditions when running code. /// - public static partial class ThrowHelper + public static partial class Guard { /// - /// Throws an when fails. + /// Helper methods to efficiently throw exceptions. /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForCanRead(Stream stream, string name) + private static partial class ThrowHelper { - throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support reading", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForCanRead(Stream stream, string name) + { + throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support reading", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) - { - throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support writing", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) + { + throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support writing", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) - { - throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support seeking", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) + { + throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support seeking", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) - { - throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) must be at position {AssertString(0)}, was at {AssertString(stream.Position)}", name); + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) + { + throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) must be at position {AssertString(0)}, was at {AssertString(stream.Position)}", name); + } } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.String.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.String.ThrowHelper.cs index 49bfa4eba86..e4ef188fca0 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.String.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.String.ThrowHelper.cs @@ -8,170 +8,176 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to efficiently throw exceptions. + /// Helper methods to verify conditions when running code. /// - public static partial class ThrowHelper + public static partial class Guard { /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must be null or empty, was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be null or empty, was {(text is null ? "null" : "empty")}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNullOrWhiteSpace(string? text, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must be null or whitespace, was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotNullOrWhiteSpace(string? text, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be null or whitespace, was {(text is null ? "null" : "whitespace")}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsEmpty(string text, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must be empty, was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be empty", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsWhiteSpace(string text, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must be whitespace, was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotWhiteSpace(string text, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be whitespace, was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size equal to {size}, had a size of {text.Length} and was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must not have a size equal to {size}, was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size over {size}, had a size of {text.Length} and was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size of at least {size}, had a size of {text.Length} and was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size less than {size}, had a size of {text.Length} and was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {AssertString(text)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} (string) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name) - { - throw new ArgumentException($"The source {AssertString(name)} (string) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(text.Length)} to be a valid index for the target string, was {AssertString(index)}"); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) - { - throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(text.Length)} to be an invalid index for the target string, was {AssertString(index)}"); + /// Helper methods to efficiently throw exceptions. + /// + private static partial class ThrowHelper + { + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must be null or empty, was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be null or empty, was {(text is null ? "null" : "empty")}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNullOrWhiteSpace(string? text, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must be null or whitespace, was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotNullOrWhiteSpace(string? text, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be null or whitespace, was {(text is null ? "null" : "whitespace")}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsEmpty(string text, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must be empty, was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be empty", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsWhiteSpace(string text, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must be whitespace, was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotWhiteSpace(string text, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be whitespace, was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size equal to {size}, had a size of {text.Length} and was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must not have a size equal to {size}, was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size over {size}, had a size of {text.Length} and was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size of at least {size}, had a size of {text.Length} and was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size less than {size}, had a size of {text.Length} and was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {AssertString(text)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} (string) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name) + { + throw new ArgumentException($"The source {AssertString(name)} (string) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(text.Length)} to be a valid index for the target string, was {AssertString(index)}"); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) + { + throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(text.Length)} to be an invalid index for the target string, was {AssertString(index)}"); + } } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Tasks.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Tasks.ThrowHelper.cs index 0f3577ca08b..a6b9de57009 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.Tasks.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.Tasks.ThrowHelper.cs @@ -10,98 +10,104 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to efficiently throw exceptions. + /// Helper methods to verify conditions when running code. /// - public static partial class ThrowHelper + public static partial class Guard { /// - /// Throws an when fails. + /// Helper methods to efficiently throw exceptions. /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsCompleted(Task task, string name) + private static partial class ThrowHelper { - throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be completed, had status {AssertString(task.Status)}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsCompleted(Task task, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be completed, had status {AssertString(task.Status)}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be completed, had status {AssertString(task.Status)}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be completed, had status {AssertString(task.Status)}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be completed successfully, had status {AssertString(task.Status)}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be completed successfully, had status {AssertString(task.Status)}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {AssertString(task.Status)}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {AssertString(task.Status)}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsFaulted(Task task, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be faulted, had status {AssertString(task.Status)}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsFaulted(Task task, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be faulted, had status {AssertString(task.Status)}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be faulted, had status {AssertString(task.Status)}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be faulted, had status {AssertString(task.Status)}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsCanceled(Task task, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be canceled, had status {AssertString(task.Status)}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsCanceled(Task task, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be canceled, had status {AssertString(task.Status)}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be canceled, had status {AssertString(task.Status)}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be canceled, had status {AssertString(task.Status)}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must have status {status}, had status {AssertString(task.Status)}", name); - } + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must have status {status}, had status {AssertString(task.Status)}", name); + } - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not have status {AssertString(status)}", name); + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not have status {AssertString(status)}", name); + } } } } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/Guard.ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/Internals/Guard.ThrowHelper.cs index 452319425df..11cbcda3e82 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/Guard.ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/Guard.ThrowHelper.cs @@ -10,190 +10,196 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to efficiently throw exceptions. + /// Helper methods to verify conditions when running code. /// - public static partial class ThrowHelper + public static partial class Guard { /// - /// Returns a formatted representation of the input value. + /// Helper methods to efficiently throw exceptions. /// - /// The input to format. - /// A formatted representation of to display in error messages. - [Pure] - private static string AssertString(object? obj) + private static partial class ThrowHelper { - return obj switch + /// + /// Returns a formatted representation of the input value. + /// + /// The input to format. + /// A formatted representation of to display in error messages. + [Pure] + private static string AssertString(object? obj) { - string _ => $"\"{obj}\"", - null => "null", - _ => $"<{obj}>" - }; - } - - /// - /// Throws an when (where is ) fails. - /// - /// The type of the input value. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNull(T value, string name) - where T : class - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be null, was {AssertString(value)} ({value.GetType().ToTypeString()})", name); - } - - /// - /// Throws an when (where is ) fails. - /// - /// The type of the input value. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNull(T? value, string name) - where T : struct - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T?).ToTypeString()}) must be null, was {AssertString(value)} ({typeof(T).ToTypeString()})", name); - } - - /// - /// Throws an when fails. - /// - /// The type of the input value. - [DoesNotReturn] - internal static void ThrowArgumentNullExceptionForIsNotNull(string name) - { - throw new ArgumentNullException(name, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be not null)"); - } - - /// - /// Throws an when fails. - /// - /// The type of the input value. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsOfType(object value, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); - } - - /// - /// Throws an when fails. - /// - /// The type of the input value. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotOfType(object value, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); - } - - /// - /// Throws an when fails. - /// - /// The type being checked against. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); - } - - /// - /// Throws an when fails. - /// - /// The type being checked against. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); - } - - /// - /// Throws an when fails. - /// - /// The type of input value being compared. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) - where T : class - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be the same instance as the target object", name); - } - - /// - /// Throws an when fails. - /// - /// The type of input value being compared. - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) - where T : class - { - throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be the same instance as the target object", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsTrue(string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} must be true, was false", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsTrue(string name, string message) - { - throw new ArgumentException($"Parameter {AssertString(name)} must be true, was false: {AssertString(message)}", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsFalse(string name) - { - throw new ArgumentException($"Parameter {AssertString(name)} must be false, was true", name); - } - - /// - /// Throws an when fails. - /// - [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsFalse(string name, string message) - { - throw new ArgumentException($"Parameter {AssertString(name)} must be false, was true: {AssertString(message)}", name); + return obj switch + { + string _ => $"\"{obj}\"", + null => "null", + _ => $"<{obj}>" + }; + } + + /// + /// Throws an when (where is ) fails. + /// + /// The type of the input value. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNull(T value, string name) + where T : class + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be null, was {AssertString(value)} ({value.GetType().ToTypeString()})", name); + } + + /// + /// Throws an when (where is ) fails. + /// + /// The type of the input value. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNull(T? value, string name) + where T : struct + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T?).ToTypeString()}) must be null, was {AssertString(value)} ({typeof(T).ToTypeString()})", name); + } + + /// + /// Throws an when fails. + /// + /// The type of the input value. + [DoesNotReturn] + public static void ThrowArgumentNullExceptionForIsNotNull(string name) + { + throw new ArgumentNullException(name, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be not null)"); + } + + /// + /// Throws an when fails. + /// + /// The type of the input value. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsOfType(object value, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); + } + + /// + /// Throws an when fails. + /// + /// The type of the input value. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotOfType(object value, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); + } + + /// + /// Throws an when fails. + /// + /// The type being checked against. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); + } + + /// + /// Throws an when fails. + /// + /// The type being checked against. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}", name); + } + + /// + /// Throws an when fails. + /// + /// The type of input value being compared. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) + where T : class + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be the same instance as the target object", name); + } + + /// + /// Throws an when fails. + /// + /// The type of input value being compared. + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) + where T : class + { + throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be the same instance as the target object", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsTrue(string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} must be true, was false", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsTrue(string name, string message) + { + throw new ArgumentException($"Parameter {AssertString(name)} must be true, was false: {AssertString(message)}", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsFalse(string name) + { + throw new ArgumentException($"Parameter {AssertString(name)} must be false, was true", name); + } + + /// + /// Throws an when fails. + /// + [DoesNotReturn] + public static void ThrowArgumentExceptionForIsFalse(string name, string message) + { + throw new ArgumentException($"Parameter {AssertString(name)} must be false, was true: {AssertString(message)}", name); + } } } } From 467bc3b20634e42de6ad87eb3b55d872ea77ec8f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 9 Dec 2020 23:18:11 +0100 Subject: [PATCH 11/12] Bumped MSBuild.Sdk.Extras package version --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index 80d84a257c6..a3d78890e48 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "msbuild-sdks": { - "MSBuild.Sdk.Extras": "2.0.54" + "MSBuild.Sdk.Extras": "3.0.22" } } \ No newline at end of file From 436273876b2d2b7a33c3faeb47527e9433bb2878 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 10 Dec 2020 01:24:07 +0100 Subject: [PATCH 12/12] Revert "Minor code tweaks" to fix .NET Native error This reverts commit 6ace41b2b854f4b93f18a3d81989837ec85b5b7c to work around a .NET Native compiler bug causing a crash. See more details in https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3573#issuecomment-742131056. --- .../Diagnostics/Guard.Comparable.Generic.cs | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs index 94dc8bb7aa1..8741b4c15db 100644 --- a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs @@ -112,7 +112,10 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) // so that only the right one will actually be translated into native code. if (sizeof(T) == 1) { - if (*(byte*)&value == *(byte*)&target) + byte valueByte = Unsafe.As(ref value); + byte targetByte = Unsafe.As(ref target); + + if (valueByte == targetByte) { return; } @@ -121,7 +124,10 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) } else if (sizeof(T) == 2) { - if (*(ushort*)&value == *(ushort*)&target) + ushort valueUShort = Unsafe.As(ref value); + ushort targetUShort = Unsafe.As(ref target); + + if (valueUShort == targetUShort) { return; } @@ -130,7 +136,10 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) } else if (sizeof(T) == 4) { - if (*(uint*)&value == *(uint*)&target) + uint valueUInt = Unsafe.As(ref value); + uint targetUInt = Unsafe.As(ref target); + + if (valueUInt == targetUInt) { return; } @@ -139,7 +148,10 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) } else if (sizeof(T) == 8) { - if (Bit64Compare(*(ulong*)&value, *(ulong*)&target)) + ulong valueULong = Unsafe.As(ref value); + ulong targetULong = Unsafe.As(ref target); + + if (Bit64Compare(ref valueULong, ref targetULong)) { return; } @@ -148,20 +160,26 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) } else if (sizeof(T) == 16) { - ulong* p0 = (ulong*)&value; - ulong* p1 = (ulong*)⌖ + ulong valueULong0 = Unsafe.As(ref value); + ulong targetULong0 = Unsafe.As(ref target); - if (Bit64Compare(p0[0], p1[0]) && Bit64Compare(p0[1], p1[1])) + if (Bit64Compare(ref valueULong0, ref targetULong0)) { - return; + ulong valueULong1 = Unsafe.Add(ref Unsafe.As(ref value), 1); + ulong targetULong1 = Unsafe.Add(ref Unsafe.As(ref target), 1); + + if (Bit64Compare(ref valueULong1, ref targetULong1)) + { + return; + } } ThrowHelper.ThrowArgumentExceptionForBitwiseEqualTo(value, target, name); } else { - Span valueBytes = new Span(&value, sizeof(T)); - Span targetBytes = new Span(&target, sizeof(T)); + Span valueBytes = new Span(Unsafe.AsPointer(ref value), sizeof(T)); + Span targetBytes = new Span(Unsafe.AsPointer(ref target), sizeof(T)); if (valueBytes.SequenceEqual(targetBytes)) { @@ -175,15 +193,16 @@ public static unsafe void IsBitwiseEqualTo(T value, T target, string name) // Compares 64 bits of data from two given memory locations for bitwise equality [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static unsafe bool Bit64Compare(ulong left, ulong right) + private static unsafe bool Bit64Compare(ref ulong left, ref ulong right) { // Handles 32 bit case, because using ulong is inefficient - if (sizeof(nint) == 4) + if (sizeof(IntPtr) == 4) { - uint* p0 = (uint*)&left; - uint* p1 = (uint*)&right; + ref int r0 = ref Unsafe.As(ref left); + ref int r1 = ref Unsafe.As(ref right); - return p0[0] == p1[0] && p0[1] == p1[1]; + return r0 == r1 && + Unsafe.Add(ref r0, 1) == Unsafe.Add(ref r1, 1); } return left == right;