diff --git a/Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnAttribute.cs b/Microsoft.Toolkit/Attributes/DoesNotReturnAttribute.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnAttribute.cs rename to Microsoft.Toolkit/Attributes/DoesNotReturnAttribute.cs diff --git a/Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnIfAttribute.cs b/Microsoft.Toolkit/Attributes/DoesNotReturnIfAttribute.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnIfAttribute.cs rename to Microsoft.Toolkit/Attributes/DoesNotReturnIfAttribute.cs diff --git a/Microsoft.Toolkit/Diagnostics/Attributes/NotNullAttribute.cs b/Microsoft.Toolkit/Attributes/NotNullAttribute.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Attributes/NotNullAttribute.cs rename to Microsoft.Toolkit/Attributes/NotNullAttribute.cs diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs index b0df73a80e3..1994b5fcc8c 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs @@ -16,16 +16,16 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(Span span, string name) + 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()}"); } @@ -35,7 +35,7 @@ public static void ThrowArgumentExceptionForIsEmpty(Span span, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int size, string name) + 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()}"); } @@ -45,7 +45,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, int size, string name) + 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()}"); } @@ -55,7 +55,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name) + 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()}"); } @@ -65,7 +65,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name) + 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()}"); } @@ -75,7 +75,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int size, string name) + 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()}"); } @@ -85,7 +85,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span span, int size, string name) + 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()}"); } @@ -95,7 +95,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, Span destination, string name) + 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()}"); } @@ -105,7 +105,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, Sp /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span source, Span destination, string name) + 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()}"); } @@ -115,9 +115,9 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Span span, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Span span, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -125,9 +125,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -135,7 +135,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, string name) + 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()}"); } @@ -145,7 +145,7 @@ public static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, str /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan span, int size, string name) + 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()}"); } @@ -155,7 +155,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan sp /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan span, int size, string name) + 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()}"); } @@ -165,7 +165,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name) + 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()}"); } @@ -175,7 +175,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) + 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()}"); } @@ -185,7 +185,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadO /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan span, int size, string name) + 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()}"); } @@ -195,7 +195,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan span, int size, string name) + 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()}"); } @@ -205,7 +205,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnly /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan source, Span destination, string name) + 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()}"); } @@ -215,7 +215,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan so /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan source, Span destination, string name) + 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()}"); } @@ -225,9 +225,9 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnly /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -235,9 +235,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -245,7 +245,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(Memory memory, string name) + 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()}"); } @@ -255,7 +255,7 @@ public static void ThrowArgumentExceptionForIsEmpty(Memory memory, string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, int size, string name) + 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()}"); } @@ -265,7 +265,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memory, int size, string name) + 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()}"); } @@ -275,7 +275,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memor /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name) + 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()}"); } @@ -285,7 +285,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memo /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) + 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()}"); } @@ -295,7 +295,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memor /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, int size, string name) + 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()}"); } @@ -305,7 +305,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory memory, int size, string name) + 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()}"); } @@ -315,7 +315,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, Memory destination, string name) + 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()}"); } @@ -325,7 +325,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory source, Memory destination, string name) + 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()}"); } @@ -335,9 +335,9 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -345,9 +345,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -355,7 +355,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, string name) + 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()}"); } @@ -365,7 +365,7 @@ public static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory memory, int size, string name) + 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()}"); } @@ -375,7 +375,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory memory, int size, string name) + 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()}"); } @@ -385,7 +385,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) + 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()}"); } @@ -395,7 +395,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) + 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()}"); } @@ -405,7 +405,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadO /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory memory, int size, string name) + 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()}"); } @@ -415,7 +415,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory memory, int size, string name) + 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()}"); } @@ -425,7 +425,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnly /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory source, Memory destination, string name) + 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()}"); } @@ -435,7 +435,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory source, Memory destination, string name) + 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()}"); } @@ -445,9 +445,9 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnly /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -455,9 +455,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -465,7 +465,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) + 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()}"); } @@ -475,7 +475,7 @@ public static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int size, string name) + 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()}"); } @@ -485,7 +485,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int siz /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int size, string name) + 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()}"); } @@ -495,7 +495,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name) + 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()}"); } @@ -505,7 +505,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name) + 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()}"); } @@ -515,7 +515,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] a /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int size, string name) + 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()}"); } @@ -525,7 +525,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int si /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] array, int size, string name) + 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()}"); } @@ -535,7 +535,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] arra /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] destination, string name) + 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()}"); } @@ -545,7 +545,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] de /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] source, T[] destination, string name) + 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()}"); } @@ -555,9 +555,9 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] sour /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -565,9 +565,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -575,7 +575,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(List list, string name) + 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()}"); } @@ -585,7 +585,7 @@ public static void ThrowArgumentExceptionForIsEmpty(List list, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int size, string name) + 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()}"); } @@ -595,7 +595,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, int size, string name) + 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()}"); } @@ -605,7 +605,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name) + 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()}"); } @@ -615,7 +615,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name) + 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()}"); } @@ -625,7 +625,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(List list, int size, string name) + 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()}"); } @@ -635,7 +635,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(List list, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List list, int size, string name) + 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()}"); } @@ -645,7 +645,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(List source, List destination, string name) + 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()}"); } @@ -655,7 +655,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(List source, Li /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List source, List destination, string name) + 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()}"); } @@ -665,9 +665,9 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, List list, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, List list, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -675,9 +675,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -685,7 +685,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(ICollection collection, string name) + 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()}"); } @@ -695,7 +695,7 @@ public static void ThrowArgumentExceptionForIsEmpty(ICollection collection /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection collection, int size, string name) + 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()}"); } @@ -705,7 +705,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection col /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection collection, int size, string name) + 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()}"); } @@ -715,7 +715,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection collection, int size, string name) + 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()}"); } @@ -725,7 +725,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) + 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()}"); } @@ -735,7 +735,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IColl /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(ICollection collection, int size, string name) + 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()}"); } @@ -745,7 +745,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(ICollection co /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection collection, int size, string name) + 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()}"); } @@ -755,7 +755,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollect /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection source, ICollection destination, string name) + 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()}"); } @@ -765,7 +765,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection sou /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection source, ICollection destination, string name) + 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()}"); } @@ -775,9 +775,9 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollect /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -785,9 +785,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -795,7 +795,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection collection, string name) + 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()}"); } @@ -805,7 +805,7 @@ public static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection co /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection collection, int size, string name) + 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()}"); } @@ -815,7 +815,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollectio /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollection collection, int size, string name) + 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()}"); } @@ -825,7 +825,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollec /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) + 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()}"); } @@ -835,7 +835,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyColle /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) + 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()}"); } @@ -845,7 +845,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IRead /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollection collection, int size, string name) + 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()}"); } @@ -855,7 +855,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollecti /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection collection, int size, string name) + 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()}"); } @@ -865,7 +865,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnl /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection source, ICollection destination, string name) + 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()}"); } @@ -875,7 +875,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollectio /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection source, ICollection destination, string name) + 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()}"); } @@ -885,9 +885,9 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnl /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -895,9 +895,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt index 98d72977851..731065134fc 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt @@ -13,9 +13,9 @@ using Microsoft.Toolkit.Extensions; namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { <# GenerateTextForItems(EnumerableTypes, item => @@ -26,7 +26,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(<#=item.Type#> <#=item.Name#>, string name) + 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()}"); } @@ -36,7 +36,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + 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()}"); } @@ -46,7 +46,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + 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()}"); } @@ -56,7 +56,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) + 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()}"); } @@ -66,7 +66,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + 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()}"); } @@ -76,7 +76,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(<#=item.Type#> <#=item.Name#>, int size, string name) + 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()}"); } @@ -86,7 +86,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + 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()}"); } @@ -96,7 +96,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) + 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()}"); } @@ -106,7 +106,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) + 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()}"); } @@ -116,9 +116,9 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -126,9 +126,9 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } <# }); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs similarity index 85% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs index db4b4037756..9ef29cbd440 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs @@ -12,9 +12,9 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. @@ -23,7 +23,7 @@ internal static partial class ThrowHelper /// This method is needed because can't be used as a generic type parameter. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) + internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must not be empty"); } @@ -35,7 +35,7 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) /// This method is needed because can't be used as a generic type parameter. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) + internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty"); } @@ -46,7 +46,7 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string /// The item of items in the input collection. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotEmpty(string name) + internal static void ThrowArgumentExceptionForIsNotEmpty(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty"); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs similarity index 56% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs index b2dd7d2e4c6..11b06a99890 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs @@ -12,9 +12,9 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. @@ -22,7 +22,7 @@ internal static partial class ThrowHelper /// The type of value type being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsDefault(T value, string name) + 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()}"); @@ -34,7 +34,7 @@ public static void ThrowArgumentExceptionForIsDefault(T value, string name) /// The type of value type being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotDefault(string name) + 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()}"); @@ -46,7 +46,7 @@ public static void ThrowArgumentExceptionForIsNotDefault(string name) /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name) + 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()}"); } @@ -57,20 +57,32 @@ public static void ThrowArgumentExceptionForIsEqualTo(T value, T target, stri /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name) + 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()}"); } + /// + /// 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()}>"); + } + /// /// Throws an when fails. /// /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -79,9 +91,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T m /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -90,9 +102,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T v /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -101,9 +113,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -112,9 +124,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo( /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -123,9 +135,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T mi /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + 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()}"); } /// @@ -134,9 +146,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -145,9 +157,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T mi /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -156,9 +168,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -167,9 +179,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T va /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(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/ThrowHelper.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs similarity index 82% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs index d3a2171f6a1..f249e812dc4 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs @@ -12,16 +12,16 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) + 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()}"); } @@ -31,7 +31,7 @@ public static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uin /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) + 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()}"); } @@ -41,7 +41,7 @@ public static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) + 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()}"); } @@ -51,7 +51,7 @@ public static void ThrowArgumentExceptionForIsCloseTo(long value, long target, u /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) + 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()}"); } @@ -61,7 +61,7 @@ public static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) + 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()}"); } @@ -71,7 +71,7 @@ public static void ThrowArgumentExceptionForIsCloseTo(float value, float target, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) + 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()}"); } @@ -81,7 +81,7 @@ public static void ThrowArgumentExceptionForIsNotCloseTo(float value, float targ /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) + 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()}"); } @@ -91,7 +91,7 @@ public static void ThrowArgumentExceptionForIsCloseTo(double value, double targe /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) + 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()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs similarity index 81% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs index a4f750b9b3e..442ea37c063 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs @@ -13,16 +13,16 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForCanRead(Stream stream, string name) + internal static void ThrowArgumentExceptionForCanRead(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support reading"); } @@ -32,7 +32,7 @@ public static void ThrowArgumentExceptionForCanRead(Stream stream, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) + internal static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support writing"); } @@ -42,7 +42,7 @@ public static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) + internal static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support seeking"); } @@ -52,7 +52,7 @@ public static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) + 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()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs similarity index 76% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs index d986ebb67dd..bfcbed6f835 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs @@ -11,16 +11,16 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name) + internal static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or empty, was {text.ToAssertString()}"); } @@ -30,7 +30,7 @@ public static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string n /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, string name) + 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")}"); } @@ -40,7 +40,7 @@ public static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, strin /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, string name) + internal static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or whitespace, was {text.ToAssertString()}"); } @@ -50,7 +50,7 @@ public static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, str /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotNullOrWhitespace(string? text, string name) + 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")}"); } @@ -60,7 +60,7 @@ public static void ThrowArgumentExceptionForIsNotNullOrWhitespace(string? text, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(string text, string name) + internal static void ThrowArgumentExceptionForIsEmpty(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be empty, was {text.ToAssertString()}"); } @@ -70,7 +70,7 @@ public static void ThrowArgumentExceptionForIsEmpty(string text, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) + internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be empty"); } @@ -80,7 +80,7 @@ public static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsWhitespace(string text, string name) + internal static void ThrowArgumentExceptionForIsWhitespace(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be whitespace, was {text.ToAssertString()}"); } @@ -90,7 +90,7 @@ public static void ThrowArgumentExceptionForIsWhitespace(string text, string nam /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotWhitespace(string text, string name) + internal static void ThrowArgumentExceptionForIsNotWhitespace(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be whitespace, was {text.ToAssertString()}"); } @@ -100,7 +100,7 @@ public static void ThrowArgumentExceptionForIsNotWhitespace(string text, string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name) + 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()}"); } @@ -110,7 +110,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name) + 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()}"); } @@ -120,7 +120,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name) + 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()}"); } @@ -130,7 +130,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name) + 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()}"); } @@ -140,7 +140,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string t /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name) + 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()}"); } @@ -150,7 +150,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(string text, int siz /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name) + 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()}"); } @@ -160,7 +160,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name) + 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()}"); } @@ -170,7 +170,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name) + 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()}"); } @@ -180,9 +180,9 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string sour /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } /// @@ -190,9 +190,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, st /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) { - ThrowArgumentOutOfRangeException(name, $"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()}"); + 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()}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs similarity index 83% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs index f25af5139d6..09f8db9c14b 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs @@ -13,16 +13,16 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCompleted(Task task, string name) + internal static void ThrowArgumentExceptionForIsCompleted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed, had status {task.Status.ToAssertString()}"); } @@ -32,7 +32,7 @@ public static void ThrowArgumentExceptionForIsCompleted(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name) + 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()}"); } @@ -42,7 +42,7 @@ public static void ThrowArgumentExceptionForIsNotCompleted(Task task, string nam /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name) + 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()}"); } @@ -52,7 +52,7 @@ public static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name) + 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()}"); } @@ -62,7 +62,7 @@ public static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsFaulted(Task task, string name) + internal static void ThrowArgumentExceptionForIsFaulted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be faulted, had status {task.Status.ToAssertString()}"); } @@ -72,7 +72,7 @@ public static void ThrowArgumentExceptionForIsFaulted(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) + 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()}"); } @@ -82,7 +82,7 @@ public static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCanceled(Task task, string name) + internal static void ThrowArgumentExceptionForIsCanceled(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be canceled, had status {task.Status.ToAssertString()}"); } @@ -92,7 +92,7 @@ public static void ThrowArgumentExceptionForIsCanceled(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name) + 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()}"); } @@ -102,7 +102,7 @@ public static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name) + 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()}"); } @@ -112,7 +112,7 @@ public static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStat /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) + internal static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not have status {status.ToAssertString()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs new file mode 100644 index 00000000000..fda9336b0fe --- /dev/null +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs @@ -0,0 +1,219 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.Contracts; +using System.Runtime.CompilerServices; +using Microsoft.Toolkit.Extensions; + +#nullable enable + +namespace Microsoft.Toolkit.Diagnostics +{ + /// + /// Helper methods to efficiently throw exceptions. + /// + public static partial class ThrowHelper + { + /// + /// 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 ToAssertString(this object? obj) + { + return obj switch + { + string _ => $"\"{obj}\"", + null => "null", + _ => $"<{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()})"); + } + + /// + /// 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()})"); + } + + /// + /// 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)"); + } + + /// + /// 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()}"); + } + + /// + /// 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()}"); + } + + /// + /// 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()}"); + } + + /// + /// 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()}"); + } + + /// + /// 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()}"); + } + + /// + /// 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()}"); + } + + /// + /// 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()}"); + } + + /// + /// 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()}"); + } + + /// + /// 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"); + } + + /// + /// 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"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsTrue(string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false"); + } + + /// + /// 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()}"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsFalse(string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true"); + } + + /// + /// 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()}"); + } + } +} diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs deleted file mode 100644 index 705f10fad4a..00000000000 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ /dev/null @@ -1,70 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Contracts; - -#nullable enable - -namespace Microsoft.Toolkit.Diagnostics -{ - /// - /// Helper methods to throw exceptions - /// - internal static partial class ThrowHelper - { - /// - /// 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 ToAssertString(this object? obj) - { - return obj switch - { - string _ => $"\"{obj}\"", - null => "null", - _ => $"<{obj}>" - }; - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The message to include in the exception. - /// Thrown with and . - [DoesNotReturn] - private static void ThrowArgumentException(string name, string message) - { - throw new ArgumentException(message, name); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The message to include in the exception. - /// Thrown with and . - [DoesNotReturn] - private static void ThrowArgumentNullException(string name, string message) - { - throw new ArgumentNullException(name, message); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The message to include in the exception. - /// Thrown with and . - [DoesNotReturn] - private static void ThrowArgumentOutOfRangeException(string name, string message) - { - throw new ArgumentOutOfRangeException(name, message); - } - } -} diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs index 3a25912cbca..2338f17a31d 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs @@ -3,212 +3,695 @@ // See the LICENSE file in the project root for more information. using System; +using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using Microsoft.Toolkit.Extensions; +using System.IO; +#if !NETSTANDARD1_4 +using System.Runtime.InteropServices; +#endif +using System.Threading; #nullable enable namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// - /// Throws an when (where is ) fails. + /// Throws a new . /// - /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNull(T value, string name) - where T : class + public static void ThrowArrayTypeMismatchException(string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be null, was {value.ToAssertString()} ({value.GetType().ToTypeString()})"); + throw new ArrayTypeMismatchException(message); } /// - /// Throws an when (where is ) fails. + /// Throws a new . /// - /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNull(T? value, string name) - where T : struct + public static void ThrowArrayTypeMismatchException(string message, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T?).ToTypeString()}) must be null, was {value.ToAssertString()} ({typeof(T).ToTypeString()})"); + throw new ArrayTypeMismatchException(message, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - public static void ThrowArgumentNullExceptionForIsNotNull(string name) + public static void ThrowArgumentException(string message) { - ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)"); + throw new ArgumentException(message); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsOfType(object value, string name) + public static void ThrowArgumentException(string message, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException(message, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// The message to include in the exception. + /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotOfType(object value, string name) + public static void ThrowArgumentException(string name, string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException(message, name); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) + public static void ThrowArgumentException(string name, string message, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentException(message, name, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// Thrown with the specified parameter. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) + public static void ThrowArgumentNullException(string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentNullException(name); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type being checked against. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// The inner to include. + /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) + public static void ThrowArgumentNullException(string name, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentNullException(name, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type being checked against. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// The message to include in the exception. + /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) + public static void ThrowArgumentNullException(string name, string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentNullException(name, message); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// Thrown with the specified parameter. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) + public static void ThrowArgumentOutOfRangeException(string name) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentOutOfRangeException(name); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// The inner to include. + /// Thrown with the specified parameter. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) + public static void ThrowArgumentOutOfRangeException(string name, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new ArgumentOutOfRangeException(name, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of input values being compared. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// The message to include in the exception. + /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowArgumentExceptionForBitwiseEqualTo(T value, T target, string name) - where T : unmanaged + public static void ThrowArgumentOutOfRangeException(string name, string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>"); + throw new ArgumentOutOfRangeException(name, message); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of input value being compared. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// The current argument value. + /// The message to include in the exception. + /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) - where T : class + public static void ThrowArgumentOutOfRangeException(string name, object value, string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the same instance as the target object"); + throw new ArgumentOutOfRangeException(name, value, message); } +#if !NETSTANDARD1_4 /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of input value being compared. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) - where T : class + public static void ThrowExternalException(string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the same instance as the target object"); + throw new ExternalException(message); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// The inner to include. + /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsTrue(string name) + public static void ThrowExternalException(string message, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false"); + throw new ExternalException(message, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The argument name. + /// The HRESULT of the errror to include. + /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsTrue(string name, string message) + public static void ThrowExternalException(string message, int error) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}"); + throw new ExternalException(message, error); } +#endif /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsFalse(string name) + public static void ThrowFormatException(string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true"); + throw new FormatException(message); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. [DoesNotReturn] - public static void ThrowArgumentExceptionForIsFalse(string name, string message) + public static void ThrowFormatException(string message, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}"); + throw new FormatException(message, innerException); + } + +#if !NETSTANDARD1_4 + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInsufficientMemoryException(string message) + { + throw new InsufficientMemoryException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInsufficientMemoryException(string message, Exception innerException) + { + throw new InsufficientMemoryException(message, innerException); + } +#endif + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidDataException(string message) + { + throw new InvalidDataException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidDataException(string message, Exception innerException) + { + throw new InvalidDataException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidOperationException(string message) + { + throw new InvalidOperationException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidOperationException(string message, Exception innerException) + { + throw new InvalidOperationException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowLockRecursionException(string message) + { + throw new LockRecursionException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowLockRecursionException(string message, Exception innerException) + { + throw new LockRecursionException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingFieldException(string message) + { + throw new MissingFieldException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingFieldException(string message, Exception innerException) + { + throw new MissingFieldException(message, innerException); + } + +#if !NETSTANDARD1_4 + /// + /// Throws a new . + /// + /// The target class being inspected. + /// The target field being retrieved. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowMissingFieldException(string className, string fieldName) + { + throw new MissingFieldException(className, fieldName); + } +#endif + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingMemberException(string message) + { + throw new MissingMemberException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingMemberException(string message, Exception innerException) + { + throw new MissingMemberException(message, innerException); + } + +#if !NETSTANDARD1_4 + /// + /// Throws a new . + /// + /// The target class being inspected. + /// The target member being retrieved. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowMissingMemberException(string className, string memberName) + { + throw new MissingMemberException(className, memberName); + } +#endif + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingMethodException(string message) + { + throw new MissingMethodException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingMethodException(string message, Exception innerException) + { + throw new MissingMethodException(message, innerException); + } + +#if !NETSTANDARD1_4 + /// + /// Throws a new . + /// + /// The target class being inspected. + /// The target method being retrieved. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowMissingMethodException(string className, string methodName) + { + throw new MissingMethodException(className, methodName); + } +#endif + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowNotSupportedException(string message) + { + throw new NotSupportedException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowNotSupportedException(string message, Exception innerException) + { + throw new NotSupportedException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The name of the disposed object. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowObjectDisposedException(string objectName) + { + throw new ObjectDisposedException(objectName); + } + + /// + /// Throws a new . + /// + /// The name of the disposed object. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowObjectDisposedException(string objectName, Exception innerException) + { + throw new ObjectDisposedException(objectName, innerException); + } + + /// + /// Throws a new . + /// + /// The name of the disposed object. + /// The message to include in the exception. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowObjectDisposedException(string objectName, string message) + { + throw new ObjectDisposedException(objectName, message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowOperationCanceledException(string message) + { + throw new OperationCanceledException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowOperationCanceledException(string message, Exception innerException) + { + throw new OperationCanceledException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The in use. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowOperationCanceledException(CancellationToken token) + { + throw new OperationCanceledException(token); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The in use. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowOperationCanceledException(string message, CancellationToken token) + { + throw new OperationCanceledException(message, token); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// The in use. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowOperationCanceledException(string message, Exception innerException, CancellationToken token) + { + throw new OperationCanceledException(message, innerException, token); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowPlatformNotSupportedException(string message) + { + throw new PlatformNotSupportedException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowPlatformNotSupportedException(string message, Exception innerException) + { + throw new PlatformNotSupportedException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowSynchronizationLockException(string message) + { + throw new SynchronizationLockException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowSynchronizationLockException(string message, Exception innerException) + { + throw new SynchronizationLockException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowTimeoutException(string message) + { + throw new TimeoutException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowTimeoutException(string message, Exception innerException) + { + throw new TimeoutException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowUnauthorizedAccessException(string message) + { + throw new UnauthorizedAccessException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowUnauthorizedAccessException(string message, Exception innerException) + { + throw new UnauthorizedAccessException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The Win32 error code associated with this exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowWin32Exception(int error) + { + throw new Win32Exception(error); + } + + /// + /// Throws a new . + /// + /// The Win32 error code associated with this exception. + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowWin32Exception(int error, string message) + { + throw new Win32Exception(error, message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowWin32Exception(string message) + { + throw new Win32Exception(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowWin32Exception(string message, Exception innerException) + { + throw new Win32Exception(message, innerException); } } } diff --git a/UnitTests/UnitTests.Shared/Diagnostics/Test_ThrowHelper.cs b/UnitTests/UnitTests.Shared/Diagnostics/Test_ThrowHelper.cs new file mode 100644 index 00000000000..c9ac6ec63cc --- /dev/null +++ b/UnitTests/UnitTests.Shared/Diagnostics/Test_ThrowHelper.cs @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Linq; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Threading; +using Microsoft.Toolkit.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace UnitTests.Diagnostics +{ + [TestClass] + public class Test_ThrowHelper + { + /// + /// Default values to be used from tests in . + /// + private static readonly IReadOnlyDictionary DefaultValues = new Dictionary + { + [typeof(string)] = "Hello world", + [typeof(Exception)] = new Exception("Test"), + [typeof(object)] = new object(), + [typeof(int)] = 42, + [typeof(CancellationToken)] = default(CancellationToken) + }; + + [TestCategory("Guard")] + [TestMethod] + [DataRow(typeof(ArrayTypeMismatchException))] + [DataRow(typeof(ArgumentException))] + [DataRow(typeof(ArgumentNullException))] + [DataRow(typeof(ArgumentOutOfRangeException))] + [DataRow(typeof(ExternalException))] + [DataRow(typeof(FormatException))] + [DataRow(typeof(InsufficientMemoryException))] + [DataRow(typeof(InvalidDataException))] + [DataRow(typeof(InvalidOperationException))] + [DataRow(typeof(LockRecursionException))] + [DataRow(typeof(MissingFieldException))] + [DataRow(typeof(MissingMemberException))] + [DataRow(typeof(MissingMethodException))] + [DataRow(typeof(NotSupportedException))] + [DataRow(typeof(ObjectDisposedException))] + [DataRow(typeof(OperationCanceledException))] + [DataRow(typeof(PlatformNotSupportedException))] + [DataRow(typeof(SynchronizationLockException))] + [DataRow(typeof(TimeoutException))] + [DataRow(typeof(UnauthorizedAccessException))] + [DataRow(typeof(Win32Exception))] + public void Test_ThrowHelper_Throw(Type exceptionType) + { + var methods = ( + from method in typeof(ThrowHelper).GetMethods(BindingFlags.Public | BindingFlags.Static) + where method.Name == $"Throw{exceptionType.Name}" + select method).ToArray(); + + foreach (var method in methods) + { + // Prepare the parameters with the default value + var parameters = ( + from parameter in method.GetParameters() + select DefaultValues[parameter.ParameterType]).ToArray(); + + // Invoke the throw method + try + { + method.Invoke(null, parameters); + } + catch (TargetInvocationException e) + { + Assert.IsInstanceOfType(e.InnerException, exceptionType); + } + } + } + } +} diff --git a/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems b/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems index ba35c1ad647..14147cede7e 100644 --- a/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems +++ b/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems @@ -15,6 +15,7 @@ +