Fixed Guard APIs CS8777 warnings (#3296)

* Added DoesNotReturnAttribute copy

* Added [DoesNotReturn] attributes to throw methods

* Removed warnings on .NET Standard 2.0
This commit is contained in:
Sergio Pedri
2020-05-26 09:10:33 -07:00
committed by GitHub
parent 9d7ac2ee94
commit c554cdd5db
13 changed files with 210 additions and 6 deletions
@@ -0,0 +1,19 @@
// 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.
#if !NETSTANDARD2_1
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Applied to a method that will never return under any circumstance.
/// </summary>
/// <remarks>Internal copy of the .NET Standard 2.1 attribute.</remarks>
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
internal sealed class DoesNotReturnAttribute : Attribute
{
}
}
#endif
@@ -14,12 +14,6 @@ namespace System.Diagnostics.CodeAnalysis
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)]
internal sealed class NotNullAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="NotNullAttribute"/> class.
/// </summary>
public NotNullAttribute()
{
}
}
}
@@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -23,6 +24,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// 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)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}");
@@ -32,6 +34,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -41,6 +44,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -50,6 +54,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -59,6 +64,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -68,6 +74,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -77,6 +84,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -86,6 +94,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -95,6 +104,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -104,6 +114,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -113,6 +124,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -122,6 +134,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// 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>(ReadOnlySpan<T> span, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}");
@@ -131,6 +144,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -140,6 +154,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -149,6 +164,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -158,6 +174,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -167,6 +184,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -176,6 +194,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -185,6 +204,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -194,6 +214,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -203,6 +224,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -212,6 +234,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -221,6 +244,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// 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>(Memory<T> memory, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory<T>).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}");
@@ -230,6 +254,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -239,6 +264,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -248,6 +274,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -257,6 +284,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -266,6 +294,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -275,6 +304,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -284,6 +314,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -293,6 +324,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -302,6 +334,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -311,6 +344,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -320,6 +354,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// 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>(ReadOnlyMemory<T> memory, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}");
@@ -329,6 +364,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -338,6 +374,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -347,6 +384,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -356,6 +394,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -365,6 +404,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -374,6 +414,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -383,6 +424,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -392,6 +434,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -401,6 +444,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -410,6 +454,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -419,6 +464,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// 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>(T[] array, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must be empty, had a size of {array.Length.ToAssertString()}");
@@ -428,6 +474,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -437,6 +484,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -446,6 +494,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -455,6 +504,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -464,6 +514,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -473,6 +524,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -482,6 +534,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -491,6 +544,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -500,6 +554,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -509,6 +564,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -518,6 +574,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// 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>(List<T> list, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List<T>).ToTypeString()}) must be empty, had a size of {list.Count.ToAssertString()}");
@@ -527,6 +584,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -536,6 +594,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -545,6 +604,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -554,6 +614,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -563,6 +624,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -572,6 +634,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -581,6 +644,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -590,6 +654,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -599,6 +664,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -608,6 +674,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -617,6 +684,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// 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>(ICollection<T> collection, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection<T>).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}");
@@ -626,6 +694,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -635,6 +704,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -644,6 +714,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -653,6 +724,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -662,6 +734,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -671,6 +744,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -680,6 +754,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -689,6 +764,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -698,6 +774,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -707,6 +784,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -716,6 +794,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// 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>(IReadOnlyCollection<T> collection, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}");
@@ -725,6 +804,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -734,6 +814,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -743,6 +824,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -752,6 +834,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -761,6 +844,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -770,6 +854,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -779,6 +864,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -788,6 +874,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -797,6 +884,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -806,6 +894,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -4,6 +4,7 @@
<#@include file="TypeInfo.ttinclude" #>
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -24,6 +25,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// 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>(<#=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()}");
@@ -33,6 +35,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -42,6 +45,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -51,6 +55,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -60,6 +65,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -69,6 +75,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -78,6 +85,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -87,6 +95,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -96,6 +105,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -105,6 +115,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -114,6 +125,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -43,7 +43,9 @@ namespace Microsoft.Toolkit.Diagnostics
{
ThrowHelper.ThrowArgumentExceptionForIsNotNullOrEmpty(text, name);
}
#pragma warning disable CS8777 // Does not return when text is null (.NET Standard 2.0 string.IsNullOrEmpty lacks flow attribute)
}
#pragma warning restore CS8777
/// <summary>
/// Asserts that the input <see cref="string"/> instance must be <see langword="null"/> or whitespace.
@@ -73,7 +75,9 @@ namespace Microsoft.Toolkit.Diagnostics
{
ThrowHelper.ThrowArgumentExceptionForIsNotNullOrWhitespace(text, name);
}
#pragma warning disable CS8777 // Does not return when text is null
}
#pragma warning restore CS8777
/// <summary>
/// Asserts that the input <see cref="string"/> instance must be empty.
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -21,6 +22,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <typeparam name="T">The item of items in the input <see cref="Span{T}"/> instance.</typeparam>
/// <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)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must not be empty");
@@ -32,6 +34,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <typeparam name="T">The item of items in the input <see cref="ReadOnlySpan{T}"/> instance.</typeparam>
/// <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)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must not be empty");
@@ -42,6 +45,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The item of items in the input collection.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNotEmpty<T>(string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty");
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -20,6 +21,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
where T : struct
{
@@ -31,6 +33,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
where T : struct
{
@@ -42,6 +45,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be equal to {target.ToAssertString()}, was {value.ToAssertString()}");
@@ -52,6 +56,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be equal to {target.ToAssertString()}, was {value.ToAssertString()}");
@@ -62,6 +67,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </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)
{
ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}");
@@ -72,6 +78,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}");
@@ -82,6 +89,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}");
@@ -92,6 +100,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}");
@@ -102,6 +111,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}");
@@ -112,6 +122,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}");
@@ -122,6 +133,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}");
@@ -132,6 +144,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}");
@@ -142,6 +155,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}");
@@ -152,6 +166,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <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)
{
ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}");
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -19,6 +20,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// 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)
{
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()}");
@@ -28,6 +30,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotCloseTo(int,int,uint,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -37,6 +40,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsCloseTo(long,long,ulong,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -46,6 +50,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotCloseTo(long,long,ulong,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -55,6 +60,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsCloseTo(float,float,float,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -64,6 +70,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotCloseTo(float,float,float,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -73,6 +80,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsCloseTo(double,double,double,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -82,6 +90,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotCloseTo(double,double,double,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -20,6 +21,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.CanRead"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForCanRead(Stream stream, string name)
{
ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support reading");
@@ -29,6 +31,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.CanWrite"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForCanWrite(Stream stream, string name)
{
ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support writing");
@@ -38,6 +41,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.CanSeek"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForCanSeek(Stream stream, string name)
{
ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support seeking");
@@ -47,6 +51,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsAtStartPosition"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
#nullable enable
@@ -18,6 +19,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNullOrEmpty"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or empty, was {text.ToAssertString()}");
@@ -27,6 +29,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotNullOrEmpty"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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")}");
@@ -36,6 +39,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNullOrWhitespace"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or whitespace, was {text.ToAssertString()}");
@@ -45,6 +49,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotNullOrWhitespace"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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")}");
@@ -54,6 +59,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsEmpty"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsEmpty(string text, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be empty, was {text.ToAssertString()}");
@@ -63,6 +69,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotEmpty"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNotEmpty(string text, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be empty");
@@ -72,6 +79,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsWhitespace"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsWhitespace(string text, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be whitespace, was {text.ToAssertString()}");
@@ -81,6 +89,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotWhitespace"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNotWhitespace(string text, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be whitespace, was {text.ToAssertString()}");
@@ -90,6 +99,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo(string,int,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -99,6 +109,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -108,6 +119,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -117,6 +129,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -126,6 +139,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -135,6 +149,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo(string,int,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -144,6 +159,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo(string,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -153,6 +169,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo(string,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -162,6 +179,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor(int,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -171,6 +189,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor(int,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Toolkit.Extensions;
@@ -20,6 +21,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsCompleted"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsCompleted(Task task, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed, had status {task.Status.ToAssertString()}");
@@ -29,6 +31,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotCompleted"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed, had status {task.Status.ToAssertString()}");
@@ -38,6 +41,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsCompletedSuccessfully"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed successfully, had status {task.Status.ToAssertString()}");
@@ -47,6 +51,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotCompletedSuccessfully"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -56,6 +61,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsFaulted"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsFaulted(Task task, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be faulted, had status {task.Status.ToAssertString()}");
@@ -65,6 +71,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotFaulted"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be faulted, had status {task.Status.ToAssertString()}");
@@ -74,6 +81,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsCanceled"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsCanceled(Task task, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be canceled, had status {task.Status.ToAssertString()}");
@@ -83,6 +91,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotCanceled"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be canceled, had status {task.Status.ToAssertString()}");
@@ -92,6 +101,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasStatusEqualTo"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -101,6 +111,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasStatusNotEqualTo"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not have status {status.ToAssertString()}");
@@ -3,6 +3,7 @@
// 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;
@@ -38,6 +39,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentException">Thrown with <paramref name="message"/> and <paramref name="name"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DoesNotReturn]
private static void ThrowArgumentException(string name, string message)
{
throw new ArgumentException(message, name);
@@ -50,6 +52,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentNullException">Thrown with <paramref name="name"/> and <paramref name="message"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DoesNotReturn]
private static void ThrowArgumentNullException(string name, string message)
{
throw new ArgumentNullException(name, message);
@@ -62,6 +65,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown with <paramref name="name"/> and <paramref name="message"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DoesNotReturn]
private static void ThrowArgumentOutOfRangeException(string name, string message)
{
throw new ArgumentOutOfRangeException(name, message);
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -20,6 +21,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The type of the input value.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNull<T>(T value, string name)
where T : class
{
@@ -31,6 +33,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The type of the input value.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNull<T>(T? value, string name)
where T : struct
{
@@ -42,6 +45,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The type of the input value.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentNullExceptionForIsNotNull<T>(string name)
{
ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)");
@@ -52,6 +56,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The type of the input value.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsOfType<T>(object value, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}");
@@ -62,6 +67,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The type of the input value.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -71,6 +77,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsOfType"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}");
@@ -80,6 +87,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotOfType"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -90,6 +98,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The type being checked against.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -100,6 +109,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The type being checked against.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -109,6 +119,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsAssignableToType"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -118,6 +129,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsAssignableToType"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public 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()}");
@@ -128,6 +140,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The type of input values being compared.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForsBitwiseEqualTo<T>(T value, T target, string name)
where T : unmanaged
{
@@ -139,6 +152,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The type of input value being compared.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsReferenceEqualTo<T>(string name)
where T : class
{
@@ -150,6 +164,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// </summary>
/// <typeparam name="T">The type of input value being compared.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsReferenceNotEqualTo<T>(string name)
where T : class
{
@@ -160,6 +175,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsTrue(bool,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsTrue(string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false");
@@ -169,6 +185,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsTrue(bool,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsTrue(string name, string message)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}");
@@ -178,6 +195,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsFalse(bool,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsFalse(string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true");
@@ -187,6 +205,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsFalse(bool,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsFalse(string name, string message)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}");