mirror of
https://github.com/chylex/.NET-Community-Toolkit.git
synced 2025-04-13 20:15:45 +02:00
Merge branch 'master' into minor-codegen-fix
This commit is contained in:
commit
94e81989ee
Microsoft.Toolkit
Attributes
Diagnostics
UnitTests/UnitTests.Shared
@ -16,16 +16,16 @@
|
||||
namespace Microsoft.Toolkit.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to throw exceptions
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
internal static partial class ThrowHelper
|
||||
public static partial class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsEmpty{T}(T[],string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(Span<T> span, string name)
|
||||
internal static void ThrowArgumentExceptionForIsEmpty<T>(Span<T> span, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -35,7 +35,7 @@ public static void ThrowArgumentExceptionForIsEmpty<T>(Span<T> span, string name
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(Span<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(Span<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -45,7 +45,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(Span<T> span, int
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(Span<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(Span<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -55,7 +55,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(Span<T> span, i
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(Span<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(Span<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -65,7 +65,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(Span<T> span,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(Span<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(Span<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -75,7 +75,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(Span<
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(Span<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThan<T>(Span<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -85,7 +85,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan<T>(Span<T> span, int
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(Span<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(Span<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).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<T>(Span<T>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(Span<T> source, Span<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(Span<T> source, Span<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Span<T>).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<T>(Span<T> source, Sp
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(Span<T> source, Span<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(Span<T> source, Span<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Span<T>).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<T>(Span<T>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, Span<T> span, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, Span<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -125,9 +125,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, Span<T> span, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, Span<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -135,7 +135,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int ind
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(ReadOnlySpan<T> span, string name)
|
||||
internal static void ThrowArgumentExceptionForIsEmpty<T>(ReadOnlySpan<T> span, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -145,7 +145,7 @@ public static void ThrowArgumentExceptionForIsEmpty<T>(ReadOnlySpan<T> span, str
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -155,7 +155,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ReadOnlySpan<T> sp
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -165,7 +165,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(ReadOnlySpan<T>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -175,7 +175,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ReadOnlySpan<T
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -185,7 +185,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ReadO
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThan<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}");
|
||||
}
|
||||
@ -195,7 +195,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan<T>(ReadOnlySpan<T> s
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ReadOnlySpan<T> span, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).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<T>(ReadOnly
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ReadOnlySpan<T> source, Span<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ReadOnlySpan<T> source, Span<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).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<T>(ReadOnlySpan<T> so
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ReadOnlySpan<T> source, Span<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ReadOnlySpan<T> source, Span<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).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<T>(ReadOnly
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, ReadOnlySpan<T> span, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, ReadOnlySpan<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -235,9 +235,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, ReadOnlySpan<T> span, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, ReadOnlySpan<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -245,7 +245,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int ind
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(Memory<T> memory, string name)
|
||||
internal static void ThrowArgumentExceptionForIsEmpty<T>(Memory<T> memory, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory<T>).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -255,7 +255,7 @@ public static void ThrowArgumentExceptionForIsEmpty<T>(Memory<T> memory, string
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(Memory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(Memory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory<T>).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -265,7 +265,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(Memory<T> memory,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(Memory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(Memory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory<T>).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -275,7 +275,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(Memory<T> memor
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(Memory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(Memory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory<T>).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -285,7 +285,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(Memory<T> memo
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(Memory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(Memory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory<T>).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -295,7 +295,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(Memor
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(Memory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThan<T>(Memory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory<T>).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -305,7 +305,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan<T>(Memory<T> memory,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(Memory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(Memory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory<T>).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<T>(Memory<T
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(Memory<T> source, Memory<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(Memory<T> source, Memory<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Memory<T>).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<T>(Memory<T> source,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(Memory<T> source, Memory<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(Memory<T> source, Memory<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Memory<T>).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<T>(Memory<T
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, Memory<T> memory, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, Memory<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -345,9 +345,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, Memory<T> memory, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, Memory<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -355,7 +355,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int ind
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(ReadOnlyMemory<T> memory, string name)
|
||||
internal static void ThrowArgumentExceptionForIsEmpty<T>(ReadOnlyMemory<T> memory, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -365,7 +365,7 @@ public static void ThrowArgumentExceptionForIsEmpty<T>(ReadOnlyMemory<T> memory,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -375,7 +375,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ReadOnlyMemory<T>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -385,7 +385,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(ReadOnlyMemory<
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -395,7 +395,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ReadOnlyMemory
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -405,7 +405,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ReadO
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThan<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}");
|
||||
}
|
||||
@ -415,7 +415,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan<T>(ReadOnlyMemory<T>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ReadOnlyMemory<T> memory, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).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<T>(ReadOnly
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ReadOnlyMemory<T> source, Memory<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ReadOnlyMemory<T> source, Memory<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).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<T>(ReadOnlyMemory<T>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ReadOnlyMemory<T> source, Memory<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ReadOnlyMemory<T> source, Memory<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).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<T>(ReadOnly
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, ReadOnlyMemory<T> memory, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, ReadOnlyMemory<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -455,9 +455,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, ReadOnlyMemory<T> memory, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, ReadOnlyMemory<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -465,7 +465,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int ind
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(T[] array, string name)
|
||||
internal static void ThrowArgumentExceptionForIsEmpty<T>(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>(T[] array, string name)
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(T[] array, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(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>(T[] array, int siz
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(T[] array, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(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>(T[] array, int
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(T[] array, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(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>(T[] array, int
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(T[] array, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(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>(T[] a
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(T[] array, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThan<T>(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>(T[] array, int si
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(T[] array, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(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>(T[] arra
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(T[] source, T[] destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(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>(T[] source, T[] de
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(T[] source, T[] destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(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>(T[] sour
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, T[] array, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -565,9 +565,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, T[] array, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -575,7 +575,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int ind
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(List<T> list, string name)
|
||||
internal static void ThrowArgumentExceptionForIsEmpty<T>(List<T> list, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List<T>).ToTypeString()}) must be empty, had a size of {list.Count.ToAssertString()}");
|
||||
}
|
||||
@ -585,7 +585,7 @@ public static void ThrowArgumentExceptionForIsEmpty<T>(List<T> list, string name
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(List<T> list, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(List<T> list, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List<T>).ToTypeString()}) must have a size equal to {size}, had a size of {list.Count.ToAssertString()}");
|
||||
}
|
||||
@ -595,7 +595,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(List<T> list, int
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(List<T> list, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(List<T> list, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List<T>).ToTypeString()}) must have a size not equal to {size}, had a size of {list.Count.ToAssertString()}");
|
||||
}
|
||||
@ -605,7 +605,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(List<T> list, i
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(List<T> list, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(List<T> list, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List<T>).ToTypeString()}) must have a size over {size}, had a size of {list.Count.ToAssertString()}");
|
||||
}
|
||||
@ -615,7 +615,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(List<T> list,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(List<T> list, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(List<T> list, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List<T>).ToTypeString()}) must have a size of at least {size}, had a size of {list.Count.ToAssertString()}");
|
||||
}
|
||||
@ -625,7 +625,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(List<
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(List<T> list, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThan<T>(List<T> list, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List<T>).ToTypeString()}) must have a size less than {size}, had a size of {list.Count.ToAssertString()}");
|
||||
}
|
||||
@ -635,7 +635,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan<T>(List<T> list, int
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(List<T> list, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(List<T> list, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List<T>).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<T>(List<T>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(List<T> source, List<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(List<T> source, List<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(List<T>).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<T>(List<T> source, Li
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(List<T> source, List<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(List<T> source, List<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(List<T>).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<T>(List<T>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, List<T> list, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, List<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -675,9 +675,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, List<T> list, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, List<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -685,7 +685,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int ind
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(ICollection<T> collection, string name)
|
||||
internal static void ThrowArgumentExceptionForIsEmpty<T>(ICollection<T> collection, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection<T>).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -695,7 +695,7 @@ public static void ThrowArgumentExceptionForIsEmpty<T>(ICollection<T> collection
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ICollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ICollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection<T>).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -705,7 +705,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ICollection<T> col
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(ICollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(ICollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection<T>).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -715,7 +715,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(ICollection<T>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ICollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ICollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection<T>).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -725,7 +725,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ICollection<T>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ICollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ICollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection<T>).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -735,7 +735,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(IColl
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(ICollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThan<T>(ICollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection<T>).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -745,7 +745,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan<T>(ICollection<T> co
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ICollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ICollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection<T>).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<T>(ICollect
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ICollection<T> source, ICollection<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(ICollection<T> source, ICollection<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ICollection<T>).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<T>(ICollection<T> sou
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ICollection<T> source, ICollection<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(ICollection<T> source, ICollection<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ICollection<T>).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<T>(ICollect
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, ICollection<T> collection, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, ICollection<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -785,9 +785,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, ICollection<T> collection, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, ICollection<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -795,7 +795,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int ind
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(IReadOnlyCollection<T> collection, string name)
|
||||
internal static void ThrowArgumentExceptionForIsEmpty<T>(IReadOnlyCollection<T> collection, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -805,7 +805,7 @@ public static void ThrowArgumentExceptionForIsEmpty<T>(IReadOnlyCollection<T> co
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -815,7 +815,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(IReadOnlyCollectio
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -825,7 +825,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(IReadOnlyCollec
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -835,7 +835,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(IReadOnlyColle
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -845,7 +845,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(IRead
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThan<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}");
|
||||
}
|
||||
@ -855,7 +855,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan<T>(IReadOnlyCollecti
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(IReadOnlyCollection<T> collection, int size, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).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<T>(IReadOnl
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(IReadOnlyCollection<T> source, ICollection<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(IReadOnlyCollection<T> source, ICollection<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).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<T>(IReadOnlyCollectio
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(IReadOnlyCollection<T> source, ICollection<T> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(IReadOnlyCollection<T> source, ICollection<T> destination, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).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<T>(IReadOnl
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, IReadOnlyCollection<T> collection, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, IReadOnlyCollection<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -895,9 +895,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index,
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, IReadOnlyCollection<T> collection, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, IReadOnlyCollection<T> 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<T>).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<T>).ToTypeString()}), was {index.ToAssertString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ using Microsoft.Toolkit.Extensions;
|
||||
namespace Microsoft.Toolkit.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to throw exceptions
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
internal static partial class ThrowHelper
|
||||
public static partial class ThrowHelper
|
||||
{
|
||||
<#
|
||||
GenerateTextForItems(EnumerableTypes, item =>
|
||||
@ -26,7 +26,7 @@ GenerateTextForItems(EnumerableTypes, item =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(<#=item.Type#> <#=item.Name#>, string name)
|
||||
internal static void ThrowArgumentExceptionForIsEmpty<T>(<#=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 =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=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 =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(<#=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 =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(<#=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 =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(<#=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 =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThan<T>(<#=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 =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=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 =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=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 =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
|
||||
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=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 =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -126,9 +126,9 @@ GenerateTextForItems(EnumerableTypes, item =>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(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()}");
|
||||
}
|
||||
<#
|
||||
});
|
||||
|
@ -12,9 +12,9 @@
|
||||
namespace Microsoft.Toolkit.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to throw exceptions
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
internal static partial class ThrowHelper
|
||||
public static partial class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotEmpty{T}(Span{T},string)"/> fails.
|
||||
@ -23,7 +23,7 @@ internal static partial class ThrowHelper
|
||||
/// <remarks>This method is needed because <see cref="Span{T}"/> can't be used as a generic type parameter.</remarks>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(string name)
|
||||
internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must not be empty");
|
||||
}
|
||||
@ -35,7 +35,7 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(string name)
|
||||
/// <remarks>This method is needed because <see cref="ReadOnlySpan{T}"/> can't be used as a generic type parameter.</remarks>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(string name)
|
||||
internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must not be empty");
|
||||
}
|
||||
@ -46,7 +46,7 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(string
|
||||
/// <typeparam name="T">The item of items in the input collection.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotEmpty<T>(string name)
|
||||
internal static void ThrowArgumentExceptionForIsNotEmpty<T>(string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty");
|
||||
}
|
@ -12,9 +12,9 @@
|
||||
namespace Microsoft.Toolkit.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to throw exceptions
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
internal static partial class ThrowHelper
|
||||
public static partial class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsDefault{T}"/> fails.
|
||||
@ -22,7 +22,7 @@ internal static partial class ThrowHelper
|
||||
/// <typeparam name="T">The type of <see langword="struct"/> value type being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsDefault<T>(T value, string name)
|
||||
internal static void ThrowArgumentExceptionForIsDefault<T>(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>(T value, string name)
|
||||
/// <typeparam name="T">The type of <see langword="struct"/> value type being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotDefault<T>(string name)
|
||||
internal static void ThrowArgumentExceptionForIsNotDefault<T>(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<T>(string name)
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEqualTo<T>(T value, T target, string name)
|
||||
internal static void ThrowArgumentExceptionForIsEqualTo<T>(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>(T value, T target, stri
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotEqualTo<T>(T value, T target, string name)
|
||||
internal static void ThrowArgumentExceptionForIsNotEqualTo<T>(T value, T target, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be equal to {target.ToAssertString()}, was {value.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsBitwiseEqualTo{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of input values being compared.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForBitwiseEqualTo<T>(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()}>");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsLessThan{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsLessThan<T>(T value, T maximum, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -79,9 +91,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsLessThan<T>(T value, T m
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo<T>(T value, T maximum, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -90,9 +102,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo<T>(T v
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan<T>(T value, T minimum, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -101,9 +113,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan<T>(T value,
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo<T>(T value, T minimum, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -112,9 +124,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo<T>(
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRange<T>(T value, T minimum, T maximum, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsInRange<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -123,9 +135,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRange<T>(T value, T mi
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange<T>(T value, T minimum, T maximum, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -134,9 +146,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange<T>(T value, T
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsBetween<T>(T value, T minimum, T maximum, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsBetween<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -145,9 +157,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsBetween<T>(T value, T mi
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween<T>(T value, T minimum, T maximum, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -156,9 +168,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween<T>(T value, T
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo<T>(T value, T minimum, T maximum, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo<T>(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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -167,9 +179,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo<T>(T va
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo<T>(T value, T minimum, T maximum, string name)
|
||||
internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo<T>(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()}");
|
||||
}
|
||||
}
|
||||
}
|
@ -12,16 +12,16 @@
|
||||
namespace Microsoft.Toolkit.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to throw exceptions
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
internal static partial class ThrowHelper
|
||||
public static partial class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsCloseTo(int,int,uint,string)"/> fails.
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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,
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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,
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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()}");
|
||||
}
|
@ -13,16 +13,16 @@
|
||||
namespace Microsoft.Toolkit.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to throw exceptions
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
internal static partial class ThrowHelper
|
||||
public static partial class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.CanRead"/> fails.
|
||||
/// </summary>
|
||||
[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)
|
||||
/// </summary>
|
||||
[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)
|
||||
/// </summary>
|
||||
[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)
|
||||
/// </summary>
|
||||
[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()}");
|
||||
}
|
@ -11,16 +11,16 @@
|
||||
namespace Microsoft.Toolkit.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to throw exceptions
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
internal static partial class ThrowHelper
|
||||
public static partial class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNullOrEmpty"/> fails.
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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,
|
||||
/// </summary>
|
||||
[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)
|
||||
/// </summary>
|
||||
[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)
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -190,9 +190,9 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, st
|
||||
/// </summary>
|
||||
[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()}");
|
||||
}
|
||||
}
|
||||
}
|
@ -13,16 +13,16 @@
|
||||
namespace Microsoft.Toolkit.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to throw exceptions
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
internal static partial class ThrowHelper
|
||||
public static partial class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsCompleted"/> fails.
|
||||
/// </summary>
|
||||
[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)
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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)
|
||||
/// </summary>
|
||||
[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)
|
||||
/// </summary>
|
||||
[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)
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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
|
||||
/// </summary>
|
||||
[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()}");
|
||||
}
|
219
Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs
Normal file
219
Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
public static partial class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a formatted representation of the input value.
|
||||
/// </summary>
|
||||
/// <param name="obj">The input <see cref="object"/> to format.</param>
|
||||
/// <returns>A formatted representation of <paramref name="obj"/> to display in error messages.</returns>
|
||||
[Pure]
|
||||
private static string ToAssertString(this object? obj)
|
||||
{
|
||||
return obj switch
|
||||
{
|
||||
string _ => $"\"{obj}\"",
|
||||
null => "null",
|
||||
_ => $"<{obj}>"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNull{T}(T,string)"/> (where <typeparamref name="T"/> is <see langword="class"/>) fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsNull<T>(T value, string name)
|
||||
where T : class
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be null, was {value.ToAssertString()} ({value.GetType().ToTypeString()})");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNull{T}(T,string)"/> (where <typeparamref name="T"/> is <see langword="struct"/>) fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsNull<T>(T? value, string name)
|
||||
where T : struct
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T?).ToTypeString()}) must be null, was {value.ToAssertString()} ({typeof(T).ToTypeString()})");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentNullException"/> when <see cref="Guard.IsNotNull{T}(T,string)"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentNullExceptionForIsNotNull<T>(string name)
|
||||
{
|
||||
ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsOfType{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsOfType<T>(object value, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotOfType{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsNotOfType<T>(object value, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsOfType"/> fails.
|
||||
/// </summary>
|
||||
[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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotOfType"/> fails.
|
||||
/// </summary>
|
||||
[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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsAssignableToType{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being checked against.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsAssignableToType<T>(object value, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotAssignableToType{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being checked against.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsNotAssignableToType<T>(object value, string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsAssignableToType"/> fails.
|
||||
/// </summary>
|
||||
[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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsAssignableToType"/> fails.
|
||||
/// </summary>
|
||||
[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()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsReferenceEqualTo{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of input value being compared.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsReferenceEqualTo<T>(string name)
|
||||
where T : class
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the same instance as the target object");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsReferenceNotEqualTo{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of input value being compared.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo<T>(string name)
|
||||
where T : class
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the same instance as the target object");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsTrue(bool,string)"/> fails.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsTrue(string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsTrue(bool,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsTrue(string name, string message)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsFalse(bool,string)"/> fails.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsFalse(string name)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsFalse(bool,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[DoesNotReturn]
|
||||
internal static void ThrowArgumentExceptionForIsFalse(string name, string message)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}");
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to throw exceptions
|
||||
/// </summary>
|
||||
internal static partial class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a formatted representation of the input value.
|
||||
/// </summary>
|
||||
/// <param name="obj">The input <see cref="object"/> to format.</param>
|
||||
/// <returns>A formatted representation of <paramref name="obj"/> to display in error messages.</returns>
|
||||
[Pure]
|
||||
private static string ToAssertString(this object? obj)
|
||||
{
|
||||
return obj switch
|
||||
{
|
||||
string _ => $"\"{obj}\"",
|
||||
null => "null",
|
||||
_ => $"<{obj}>"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentException">Thrown with <paramref name="message"/> and <paramref name="name"/>.</exception>
|
||||
[DoesNotReturn]
|
||||
private static void ThrowArgumentException(string name, string message)
|
||||
{
|
||||
throw new ArgumentException(message, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentNullException"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown with <paramref name="name"/> and <paramref name="message"/>.</exception>
|
||||
[DoesNotReturn]
|
||||
private static void ThrowArgumentNullException(string name, string message)
|
||||
{
|
||||
throw new ArgumentNullException(name, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with <paramref name="name"/> and <paramref name="message"/>.</exception>
|
||||
[DoesNotReturn]
|
||||
private static void ThrowArgumentOutOfRangeException(string name, string message)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(name, message);
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to throw exceptions
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
internal static partial class ThrowHelper
|
||||
public static partial class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNull{T}(T,string)"/> (where <typeparamref name="T"/> is <see langword="class"/>) fails.
|
||||
/// Throws a new <see cref="ArrayTypeMismatchException"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArrayTypeMismatchException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNull<T>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNull{T}(T,string)"/> (where <typeparamref name="T"/> is <see langword="struct"/>) fails.
|
||||
/// Throws a new <see cref="ArrayTypeMismatchException"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ArrayTypeMismatchException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNull<T>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentNullException"/> when <see cref="Guard.IsNotNull{T}(T,string)"/> fails.
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentNullExceptionForIsNotNull<T>(string name)
|
||||
public static void ThrowArgumentException(string message)
|
||||
{
|
||||
ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)");
|
||||
throw new ArgumentException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsOfType{T}"/> fails.
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsOfType<T>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotOfType{T}"/> fails.
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotOfType<T>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsOfType"/> fails.
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotOfType"/> fails.
|
||||
/// Throws a new <see cref="ArgumentNullException"/>.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown with the specified parameter.</exception>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsAssignableToType{T}"/> fails.
|
||||
/// Throws a new <see cref="ArgumentNullException"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being checked against.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsAssignableToType<T>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotAssignableToType{T}"/> fails.
|
||||
/// Throws a new <see cref="ArgumentNullException"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being checked against.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotAssignableToType<T>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsAssignableToType"/> fails.
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameter.</exception>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsAssignableToType"/> fails.
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameter.</exception>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsBitwiseEqualTo{T}"/> fails.
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of input values being compared.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForBitwiseEqualTo<T>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsReferenceEqualTo{T}"/> fails.
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of input value being compared.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="value">The current argument value.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsReferenceEqualTo<T>(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
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ExternalException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ExternalException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowExternalException(string message)
|
||||
{
|
||||
throw new ExternalException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsReferenceNotEqualTo{T}"/> fails.
|
||||
/// Throws a new <see cref="ExternalException"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of input value being compared.</typeparam>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="message">The argument name.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ExternalException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsReferenceNotEqualTo<T>(string name)
|
||||
where T : class
|
||||
public static void ThrowExternalException(string message, Exception innerException)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the same instance as the target object");
|
||||
throw new ExternalException(message, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsTrue(bool,string)"/> fails.
|
||||
/// Throws a new <see cref="ExternalException"/>.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="message">The argument name.</param>
|
||||
/// <param name="error">The HRESULT of the errror to include.</param>
|
||||
/// <exception cref="ExternalException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsTrue(string name)
|
||||
public static void ThrowExternalException(string message, int error)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false");
|
||||
throw new ExternalException(message, error);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="FormatException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="FormatException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowFormatException(string message)
|
||||
{
|
||||
throw new FormatException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsTrue(bool,string,string)"/> fails.
|
||||
/// Throws a new <see cref="FormatException"/>.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="FormatException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsTrue(string name, string message)
|
||||
public static void ThrowFormatException(string message, Exception innerException)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}");
|
||||
throw new FormatException(message, innerException);
|
||||
}
|
||||
|
||||
#if !NETSTANDARD1_4
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InsufficientMemoryException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="InsufficientMemoryException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowInsufficientMemoryException(string message)
|
||||
{
|
||||
throw new InsufficientMemoryException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsFalse(bool,string)"/> fails.
|
||||
/// Throws a new <see cref="InsufficientMemoryException"/>.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="InsufficientMemoryException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsFalse(string name)
|
||||
public static void ThrowInsufficientMemoryException(string message, Exception innerException)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true");
|
||||
throw new InsufficientMemoryException(message, innerException);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InvalidDataException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="InvalidDataException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowInvalidDataException(string message)
|
||||
{
|
||||
throw new InvalidDataException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsFalse(bool,string,string)"/> fails.
|
||||
/// Throws a new <see cref="InvalidDataException"/>.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="InvalidDataException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsFalse(string name, string message)
|
||||
public static void ThrowInvalidDataException(string message, Exception innerException)
|
||||
{
|
||||
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}");
|
||||
throw new InvalidDataException(message, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InvalidOperationException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowInvalidOperationException(string message)
|
||||
{
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InvalidOperationException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowInvalidOperationException(string message, Exception innerException)
|
||||
{
|
||||
throw new InvalidOperationException(message, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="LockRecursionException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="LockRecursionException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowLockRecursionException(string message)
|
||||
{
|
||||
throw new LockRecursionException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="LockRecursionException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="LockRecursionException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowLockRecursionException(string message, Exception innerException)
|
||||
{
|
||||
throw new LockRecursionException(message, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingFieldException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="MissingFieldException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingFieldException(string message)
|
||||
{
|
||||
throw new MissingFieldException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingFieldException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="MissingFieldException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingFieldException(string message, Exception innerException)
|
||||
{
|
||||
throw new MissingFieldException(message, innerException);
|
||||
}
|
||||
|
||||
#if !NETSTANDARD1_4
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingFieldException"/>.
|
||||
/// </summary>
|
||||
/// <param name="className">The target class being inspected.</param>
|
||||
/// <param name="fieldName">The target field being retrieved.</param>
|
||||
/// <exception cref="MissingFieldException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingFieldException(string className, string fieldName)
|
||||
{
|
||||
throw new MissingFieldException(className, fieldName);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMemberException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="MissingMemberException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingMemberException(string message)
|
||||
{
|
||||
throw new MissingMemberException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMemberException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="MissingMemberException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingMemberException(string message, Exception innerException)
|
||||
{
|
||||
throw new MissingMemberException(message, innerException);
|
||||
}
|
||||
|
||||
#if !NETSTANDARD1_4
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMemberException"/>.
|
||||
/// </summary>
|
||||
/// <param name="className">The target class being inspected.</param>
|
||||
/// <param name="memberName">The target member being retrieved.</param>
|
||||
/// <exception cref="MissingMemberException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingMemberException(string className, string memberName)
|
||||
{
|
||||
throw new MissingMemberException(className, memberName);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMethodException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="MissingMethodException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingMethodException(string message)
|
||||
{
|
||||
throw new MissingMethodException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMethodException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="MissingMethodException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingMethodException(string message, Exception innerException)
|
||||
{
|
||||
throw new MissingMethodException(message, innerException);
|
||||
}
|
||||
|
||||
#if !NETSTANDARD1_4
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMethodException"/>.
|
||||
/// </summary>
|
||||
/// <param name="className">The target class being inspected.</param>
|
||||
/// <param name="methodName">The target method being retrieved.</param>
|
||||
/// <exception cref="MissingMethodException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingMethodException(string className, string methodName)
|
||||
{
|
||||
throw new MissingMethodException(className, methodName);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="NotSupportedException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="NotSupportedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowNotSupportedException(string message)
|
||||
{
|
||||
throw new NotSupportedException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="NotSupportedException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="NotSupportedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowNotSupportedException(string message, Exception innerException)
|
||||
{
|
||||
throw new NotSupportedException(message, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ObjectDisposedException"/>.
|
||||
/// </summary>
|
||||
/// <param name="objectName">The name of the disposed object.</param>
|
||||
/// <exception cref="ObjectDisposedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowObjectDisposedException(string objectName)
|
||||
{
|
||||
throw new ObjectDisposedException(objectName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ObjectDisposedException"/>.
|
||||
/// </summary>
|
||||
/// <param name="objectName">The name of the disposed object.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ObjectDisposedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowObjectDisposedException(string objectName, Exception innerException)
|
||||
{
|
||||
throw new ObjectDisposedException(objectName, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ObjectDisposedException"/>.
|
||||
/// </summary>
|
||||
/// <param name="objectName">The name of the disposed object.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ObjectDisposedException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowObjectDisposedException(string objectName, string message)
|
||||
{
|
||||
throw new ObjectDisposedException(objectName, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowOperationCanceledException(string message)
|
||||
{
|
||||
throw new OperationCanceledException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowOperationCanceledException(string message, Exception innerException)
|
||||
{
|
||||
throw new OperationCanceledException(message, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
/// </summary>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> in use.</param>
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowOperationCanceledException(CancellationToken token)
|
||||
{
|
||||
throw new OperationCanceledException(token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> in use.</param>
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowOperationCanceledException(string message, CancellationToken token)
|
||||
{
|
||||
throw new OperationCanceledException(message, token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> in use.</param>
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowOperationCanceledException(string message, Exception innerException, CancellationToken token)
|
||||
{
|
||||
throw new OperationCanceledException(message, innerException, token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="PlatformNotSupportedException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="PlatformNotSupportedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowPlatformNotSupportedException(string message)
|
||||
{
|
||||
throw new PlatformNotSupportedException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="PlatformNotSupportedException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="PlatformNotSupportedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowPlatformNotSupportedException(string message, Exception innerException)
|
||||
{
|
||||
throw new PlatformNotSupportedException(message, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="SynchronizationLockException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="SynchronizationLockException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowSynchronizationLockException(string message)
|
||||
{
|
||||
throw new SynchronizationLockException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="SynchronizationLockException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="SynchronizationLockException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowSynchronizationLockException(string message, Exception innerException)
|
||||
{
|
||||
throw new SynchronizationLockException(message, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="TimeoutException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="TimeoutException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowTimeoutException(string message)
|
||||
{
|
||||
throw new TimeoutException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="TimeoutException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="TimeoutException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowTimeoutException(string message, Exception innerException)
|
||||
{
|
||||
throw new TimeoutException(message, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="UnauthorizedAccessException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="UnauthorizedAccessException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowUnauthorizedAccessException(string message)
|
||||
{
|
||||
throw new UnauthorizedAccessException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="UnauthorizedAccessException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="UnauthorizedAccessException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowUnauthorizedAccessException(string message, Exception innerException)
|
||||
{
|
||||
throw new UnauthorizedAccessException(message, innerException);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="Win32Exception"/>.
|
||||
/// </summary>
|
||||
/// <param name="error">The Win32 error code associated with this exception.</param>
|
||||
/// <exception cref="Win32Exception">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowWin32Exception(int error)
|
||||
{
|
||||
throw new Win32Exception(error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="Win32Exception"/>.
|
||||
/// </summary>
|
||||
/// <param name="error">The Win32 error code associated with this exception.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="Win32Exception">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowWin32Exception(int error, string message)
|
||||
{
|
||||
throw new Win32Exception(error, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="Win32Exception"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="Win32Exception">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowWin32Exception(string message)
|
||||
{
|
||||
throw new Win32Exception(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="Win32Exception"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="Win32Exception">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowWin32Exception(string message, Exception innerException)
|
||||
{
|
||||
throw new Win32Exception(message, innerException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
82
UnitTests/UnitTests.Shared/Diagnostics/Test_ThrowHelper.cs
Normal file
82
UnitTests/UnitTests.Shared/Diagnostics/Test_ThrowHelper.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Default values to be used from tests in <see cref="Test_ThrowHelper_Throw"/>.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<Type, object> DefaultValues = new Dictionary<Type, object>
|
||||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Collections\ObservableGroupTests.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Collections\ReadOnlyObservableGroupedCollectionTests.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Collections\ReadOnlyObservableGroupTests.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Test_ThrowHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Test_Guard.Array.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Test_Guard.Comparable.Numeric.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Test_Guard.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user