Added FisheryLib.Collections.FishTable and Mono.Cecil extension methods
A bit of refactoring has been done too
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
namespace System.Diagnostics.CodeAnalysis;
|
||||
|
||||
/// <summary>
|
||||
/// Used to indicate a byref escapes and is not scoped.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// There are several cases where the C# compiler treats a <see langword="ref"/> as implicitly
|
||||
/// <see langword="scoped"/> - where the compiler does not allow the <see langword="ref"/> to escape the method.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// For example:
|
||||
/// <list type="number">
|
||||
/// <item><see langword="this"/> for <see langword="struct"/> instance methods.</item>
|
||||
/// <item><see langword="ref"/> parameters that refer to <see langword="ref"/> <see langword="struct"/> types.</item>
|
||||
/// <item><see langword="out"/> parameters.</item>
|
||||
/// </list>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This attribute is used in those instances where the <see langword="ref"/> should be allowed to escape.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Applying this attribute, in any form, has impact on consumers of the applicable API. It is necessary for
|
||||
/// API authors to understand the lifetime implications of applying this attribute and how it may impact their users.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter,
|
||||
Inherited = false)]
|
||||
internal sealed class UnscopedRefAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UnscopedRefAttribute"/> class.
|
||||
/// </summary>
|
||||
public UnscopedRefAttribute() { }
|
||||
}
|
||||
@@ -52,9 +52,7 @@ public static class TypeExtensions
|
||||
{
|
||||
// Primitive types use the keyword name
|
||||
if (BuiltInTypesMap.TryGetValue(type, out var typeName))
|
||||
{
|
||||
return typeName!;
|
||||
}
|
||||
|
||||
// Array types are displayed as Foo[]
|
||||
if (type.IsArray)
|
||||
@@ -62,7 +60,8 @@ public static class TypeExtensions
|
||||
var elementType = type.GetElementType()!;
|
||||
var rank = type.GetArrayRank();
|
||||
|
||||
return $"{FormatDisplayString(elementType, 0, elementType.GetGenericArguments())}[{new string(',', rank - 1)}]";
|
||||
return $"{FormatDisplayString(elementType, 0,
|
||||
elementType.GetGenericArguments())}[{new string(',', rank - 1)}]";
|
||||
}
|
||||
|
||||
// By checking generic types here we are only interested in specific cases,
|
||||
@@ -84,16 +83,17 @@ public static class TypeExtensions
|
||||
}
|
||||
|
||||
// ValueTuple<T1, T2> types are displayed as (T1, T2)
|
||||
if (genericTypeDefinition == typeof(ValueTuple<>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,,,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,,,,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,,,,,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,,,,,,>))
|
||||
if (genericTypeDefinition == typeof(ValueTuple<>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,,,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,,,,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,,,,,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,,,,,,>))
|
||||
{
|
||||
var formattedTypes = type.GetGenericArguments().Select(t => FormatDisplayString(t, 0, t.GetGenericArguments()));
|
||||
var formattedTypes = type.GetGenericArguments()
|
||||
.Select(static t => FormatDisplayString(t, 0, t.GetGenericArguments()));
|
||||
|
||||
return $"({string.Join(", ", formattedTypes)})";
|
||||
}
|
||||
@@ -109,7 +109,8 @@ public static class TypeExtensions
|
||||
var genericArgumentsCount = int.Parse(tokens[1]);
|
||||
var typeArgumentsOffset = typeArguments.Length - genericTypeOffset - genericArgumentsCount;
|
||||
var currentTypeArguments = typeArguments.Slice(typeArgumentsOffset, genericArgumentsCount).ToArray();
|
||||
var formattedTypes = currentTypeArguments.Select(t => FormatDisplayString(t, 0, t.GetGenericArguments()));
|
||||
var formattedTypes
|
||||
= currentTypeArguments.Select(static t => FormatDisplayString(t, 0, t.GetGenericArguments()));
|
||||
|
||||
// Standard generic types are displayed as Foo<T>
|
||||
displayName = $"{tokens[0]}<{string.Join(", ", formattedTypes)}>";
|
||||
@@ -130,7 +131,7 @@ public static class TypeExtensions
|
||||
}
|
||||
|
||||
// Atomically get or build the display string for the current type.
|
||||
return DisplayNames.GetValue(type, t =>
|
||||
return DisplayNames.GetValue(type, static t =>
|
||||
{
|
||||
// By-ref types are displayed as T&
|
||||
if (t.IsByRef)
|
||||
@@ -159,4 +160,4 @@ public static class TypeExtensions
|
||||
return FormatDisplayString(t, 0, t.GetGenericArguments());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,8 @@ public static class ValueTypeExtensions
|
||||
/// <summary>
|
||||
/// Gets the table of hex characters (doesn't allocate, maps to .text section, see <see href="https://github.com/dotnet/roslyn/pull/24621"/>).
|
||||
/// </summary>
|
||||
private static ReadOnlySpan<byte> HexCharactersTable => new[]
|
||||
{
|
||||
(byte)'0', (byte)'1', (byte)'2', (byte)'3',
|
||||
(byte)'4', (byte)'5', (byte)'6', (byte)'7',
|
||||
(byte)'8', (byte)'9', (byte)'A', (byte)'B',
|
||||
(byte)'C', (byte)'D', (byte)'E', (byte)'F'
|
||||
};
|
||||
private static ReadOnlySpan<byte> HexCharactersTable
|
||||
=> "0123456789ABCDEF"u8;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a hexadecimal <see cref="string"/> representation of a given <typeparamref name="T"/> value, left-padded and ordered as big-endian.
|
||||
@@ -42,7 +37,7 @@ public static class ValueTypeExtensions
|
||||
public static unsafe string ToHexString<T>(this T value)
|
||||
where T : unmanaged
|
||||
{
|
||||
var sizeOfT = Unsafe.SizeOf<T>();
|
||||
var sizeOfT = sizeof(T);
|
||||
var bufferSize = (2 * sizeOfT) + 2;
|
||||
var p = stackalloc char[bufferSize];
|
||||
|
||||
@@ -63,4 +58,4 @@ public static class ValueTypeExtensions
|
||||
|
||||
return new(p, 0, bufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,287 +10,287 @@ namespace PerformanceFish.Utility.Diagnostics;
|
||||
partial class Guard
|
||||
{
|
||||
<#
|
||||
GenerateTextForItems(EnumerableTypes, item =>
|
||||
{
|
||||
GenerateTextForItems(EnumerableTypes, item =>
|
||||
{
|
||||
#>
|
||||
/// <summary>
|
||||
/// Asserts that the input <#=item.XmlType#> instance must be empty.
|
||||
/// Asserts that the input <#= item.XmlType #> instance must be empty.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="<#= item.Name #>">The input <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is != 0.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#= item.Name #>"/> is != 0.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsEmpty<T>(<#=item.Type#> <#=item.Name#>, [CallerArgumentExpression("<#=item.Name#>")] string name = "")
|
||||
public static void IsEmpty<T>(<#= item.Type #> <#= item.Name #>, [CallerArgumentExpression("<#= item.Name #>")] string name = "")
|
||||
{
|
||||
if (<#=item.Name#>.<#=item.Size#> == 0)
|
||||
if (<#= item.Name #>.<#= item.Size #> == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsEmpty(<#=item.Cast#><#=item.Name#>, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForIsEmpty(<#= item.Cast #><#= item.Name #>, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input <#=item.XmlType#> instance must not be empty.
|
||||
/// Asserts that the input <#= item.XmlType #> instance must not be empty.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="<#= item.Name #>">The input <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is == 0.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#= item.Name #>"/> is == 0.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotEmpty<T>(<#=item.Type#> <#=item.Name#>, [CallerArgumentExpression("<#=item.Name#>")] string name = "")
|
||||
public static void IsNotEmpty<T>(<#= item.Type #> <#= item.Name #>, [CallerArgumentExpression("<#= item.Name #>")] string name = "")
|
||||
{
|
||||
if (<#=item.Name#>.<#=item.Size#> != 0)
|
||||
if (<#= item.Name #>.<#= item.Size #> != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
<#
|
||||
if (item.Type == "Span<T>")
|
||||
{
|
||||
if (item.Type == "Span<T>")
|
||||
{
|
||||
#>
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(name);
|
||||
<#
|
||||
}
|
||||
else if (item.Type == "ReadOnlySpan<T>")
|
||||
{
|
||||
}
|
||||
else if (item.Type == "ReadOnlySpan<T>")
|
||||
{
|
||||
#>
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(name);
|
||||
<#
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
#>
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotEmpty<<#=item.Type#>>(name);
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotEmpty<<#= item.Type #>>(name);
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input <#=item.XmlType#> instance must have a size of a specified value.
|
||||
/// Asserts that the input <#= item.XmlType #> instance must have a size of a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="<#= item.Name #>">The input <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="size">The target size to test.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is != <paramref name="size"/>.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#= item.Name #>"/> is != <paramref name="size"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, [CallerArgumentExpression("<#=item.Name#>")] string name = "")
|
||||
public static void HasSizeEqualTo<T>(<#= item.Type #> <#= item.Name #>, int size, [CallerArgumentExpression("<#= item.Name #>")] string name = "")
|
||||
{
|
||||
if (<#=item.Name#>.<#=item.Size#> == size)
|
||||
if (<#= item.Name #>.<#= item.Size #> == size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Cast#><#=item.Name#>, size, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#= item.Cast #><#= item.Name #>, size, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input <#=item.XmlType#> instance must have a size not equal to a specified value.
|
||||
/// Asserts that the input <#= item.XmlType #> instance must have a size not equal to a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="<#= item.Name #>">The input <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="size">The target size to test.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is == <paramref name="size"/>.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#= item.Name #>"/> is == <paramref name="size"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeNotEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, [CallerArgumentExpression("<#=item.Name#>")] string name = "")
|
||||
public static void HasSizeNotEqualTo<T>(<#= item.Type #> <#= item.Name #>, int size, [CallerArgumentExpression("<#= item.Name #>")] string name = "")
|
||||
{
|
||||
if (<#=item.Name#>.<#=item.Size#> != size)
|
||||
if (<#= item.Name #>.<#= item.Size #> != size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Cast#><#=item.Name#>, size, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeNotEqualTo(<#= item.Cast #><#= item.Name #>, size, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input <#=item.XmlType#> instance must have a size over a specified value.
|
||||
/// Asserts that the input <#= item.XmlType #> instance must have a size over a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="<#= item.Name #>">The input <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="size">The target size to test.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is <= <paramref name="size"/>.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#= item.Name #>"/> is <= <paramref name="size"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeGreaterThan<T>(<#=item.Type#> <#=item.Name#>, int size, [CallerArgumentExpression("<#=item.Name#>")] string name = "")
|
||||
public static void HasSizeGreaterThan<T>(<#= item.Type #> <#= item.Name #>, int size, [CallerArgumentExpression("<#= item.Name #>")] string name = "")
|
||||
{
|
||||
if (<#=item.Name#>.<#=item.Size#> > size)
|
||||
if (<#= item.Name #>.<#= item.Size #> > size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Cast#><#=item.Name#>, size, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(<#= item.Cast #><#= item.Name #>, size, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input <#=item.XmlType#> instance must have a size of at least or equal to a specified value.
|
||||
/// Asserts that the input <#= item.XmlType #> instance must have a size of at least or equal to a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="<#= item.Name #>">The input <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="size">The target size to test.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is < <paramref name="size"/>.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#= item.Name #>"/> is < <paramref name="size"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeGreaterThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, [CallerArgumentExpression("<#=item.Name#>")] string name = "")
|
||||
public static void HasSizeGreaterThanOrEqualTo<T>(<#= item.Type #> <#= item.Name #>, int size, [CallerArgumentExpression("<#= item.Name #>")] string name = "")
|
||||
{
|
||||
if (<#=item.Name#>.<#=item.Size#> >= size)
|
||||
if (<#= item.Name #>.<#= item.Size #> >= size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Cast#><#=item.Name#>, size, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#= item.Cast #><#= item.Name #>, size, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input <#=item.XmlType#> instance must have a size of less than a specified value.
|
||||
/// Asserts that the input <#= item.XmlType #> instance must have a size of less than a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="<#= item.Name #>">The input <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="size">The target size to test.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is >= <paramref name="size"/>.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#= item.Name #>"/> is >= <paramref name="size"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeLessThan<T>(<#=item.Type#> <#=item.Name#>, int size, [CallerArgumentExpression("<#=item.Name#>")] string name = "")
|
||||
public static void HasSizeLessThan<T>(<#= item.Type #> <#= item.Name #>, int size, [CallerArgumentExpression("<#= item.Name #>")] string name = "")
|
||||
{
|
||||
if (<#=item.Name#>.<#=item.Size#> < size)
|
||||
if (<#= item.Name #>.<#= item.Size #> < size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThan(<#=item.Cast#><#=item.Name#>, size, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThan(<#= item.Cast #><#= item.Name #>, size, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input <#=item.XmlType#> instance must have a size of less than or equal to a specified value.
|
||||
/// Asserts that the input <#= item.XmlType #> instance must have a size of less than or equal to a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="<#= item.Name #>">The input <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="size">The target size to test.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is > <paramref name="size"/>.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#= item.Name #>"/> is > <paramref name="size"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeLessThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, [CallerArgumentExpression("<#=item.Name#>")] string name = "")
|
||||
public static void HasSizeLessThanOrEqualTo<T>(<#= item.Type #> <#= item.Name #>, int size, [CallerArgumentExpression("<#= item.Name #>")] string name = "")
|
||||
{
|
||||
if (<#=item.Name#>.<#=item.Size#> <= size)
|
||||
if (<#= item.Name #>.<#= item.Size #> <= size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Cast#><#=item.Name#>, size, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#= item.Cast #><#= item.Name #>, size, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the source <#=item.XmlType#> instance must have the same size of a destination <#=item.XmlType#> instance.
|
||||
/// Asserts that the source <#= item.XmlType #> instance must have the same size of a destination <#= item.XmlType #> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="source">The source <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <param name="destination">The destination <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="source">The source <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="destination">The destination <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="source"/> is != the one of <paramref name="destination"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, [CallerArgumentExpression("source")] string name = "")
|
||||
public static void HasSizeEqualTo<T>(<#= item.Type #> source, <#= item.DestinationType #> destination, [CallerArgumentExpression("source")] string name = "")
|
||||
{
|
||||
if (source.<#=item.Size#> == destination.<#=item.Size#>)
|
||||
if (source.<#= item.Size #> == destination.<#= item.Size #>)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
<#
|
||||
if (item.HasCountProperty)
|
||||
{
|
||||
if (item.HasCountProperty)
|
||||
{
|
||||
#>
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Cast#>source, destination.<#=item.Size#>, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#= item.Cast #>source, destination.<#= item.Size #>, name);
|
||||
<#
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
#>
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(source, <#=item.Cast#>destination, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(source, <#= item.Cast #>destination, name);
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the source <#=item.XmlType#> instance must have a size of less than or equal to that of a destination <#=item.XmlType#> instance.
|
||||
/// Asserts that the source <#= item.XmlType #> instance must have a size of less than or equal to that of a destination <#= item.XmlType #> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="source">The source <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <param name="destination">The destination <#=item.XmlType#> instance to check the size for.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="source">The source <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="destination">The destination <#= item.XmlType #> instance to check the size for.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="source"/> is > the one of <paramref name="destination"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeLessThanOrEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, [CallerArgumentExpression("source")] string name = "")
|
||||
public static void HasSizeLessThanOrEqualTo<T>(<#= item.Type #> source, <#= item.DestinationType #> destination, [CallerArgumentExpression("source")] string name = "")
|
||||
{
|
||||
if (source.<#=item.Size#> <= destination.<#=item.Size#>)
|
||||
if (source.<#= item.Size #> <= destination.<#= item.Size #>)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
<#
|
||||
if (item.HasCountProperty)
|
||||
{
|
||||
if (item.HasCountProperty)
|
||||
{
|
||||
#>
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Cast#>source, destination.<#=item.Size#>, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#= item.Cast #>source, destination.<#= item.Size #>, name);
|
||||
<#
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
#>
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(source, <#=item.Cast#>destination, name);
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(source, <#= item.Cast #>destination, name);
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input index is valid for a given <#=item.XmlType#> instance.
|
||||
/// Asserts that the input index is valid for a given <#= item.XmlType #> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="index">The input index to be used to access <paramref name="<#=item.Name#>"/>.</param>
|
||||
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to use to validate <paramref name="index"/>.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="index">The input index to be used to access <paramref name="<#= item.Name #>"/>.</param>
|
||||
/// <param name="<#= item.Name #>">The input <#= item.XmlType #> instance to use to validate <paramref name="index"/>.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is not valid to access <paramref name="<#=item.Name#>"/>.</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is not valid to access <paramref name="<#= item.Name #>"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, [CallerArgumentExpression("index")] string name = "")
|
||||
public static void IsInRangeFor<T>(int index, <#= item.Type #> <#= item.Name #>, [CallerArgumentExpression("index")] string name = "")
|
||||
{
|
||||
<#
|
||||
// Here we're leveraging the fact that signed integers are represented
|
||||
// in 2-complement to perform the bounds check with a single compare operation.
|
||||
// This is the same trick used throughout CoreCLR as well.
|
||||
// For more info and code sample, see the original conversation here:
|
||||
// https://github.com/CommunityToolkit/WindowsCommunityToolkit/pull/3131#discussion_r390682835
|
||||
// Here we're leveraging the fact that signed integers are represented
|
||||
// in 2-complement to perform the bounds check with a single compare operation.
|
||||
// This is the same trick used throughout CoreCLR as well.
|
||||
// For more info and code sample, see the original conversation here:
|
||||
// https://github.com/CommunityToolkit/WindowsCommunityToolkit/pull/3131#discussion_r390682835
|
||||
#>
|
||||
if ((uint)index < (uint)<#=item.Name#>.<#=item.Size#>)
|
||||
if ((uint)index < (uint)<#= item.Name #>.<#= item.Size #>)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRangeFor(index, <#=item.Cast#><#=item.Name#>, name);
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRangeFor(index, <#= item.Cast #><#= item.Name #>, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input index is not valid for a given <#=item.XmlType#> instance.
|
||||
/// Asserts that the input index is not valid for a given <#= item.XmlType #> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
|
||||
/// <param name="index">The input index to be used to access <paramref name="<#=item.Name#>"/>.</param>
|
||||
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to use to validate <paramref name="index"/>.</param>
|
||||
/// <typeparam name="T">The item of items in the input <#= item.XmlType #> instance.</typeparam>
|
||||
/// <param name="index">The input index to be used to access <paramref name="<#= item.Name #>"/>.</param>
|
||||
/// <param name="<#= item.Name #>">The input <#= item.XmlType #> instance to use to validate <paramref name="index"/>.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is valid to access <paramref name="<#=item.Name#>"/>.</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is valid to access <paramref name="<#= item.Name #>"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, [CallerArgumentExpression("index")] string name = "")
|
||||
public static void IsNotInRangeFor<T>(int index, <#= item.Type #> <#= item.Name #>, [CallerArgumentExpression("index")] string name = "")
|
||||
{
|
||||
if ((uint)index >= (uint)<#=item.Name#>.<#=item.Size#>)
|
||||
if ((uint)index >= (uint)<#= item.Name #>.<#= item.Size #>)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(index, <#=item.Cast#><#=item.Name#>, name);
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(index, <#= item.Cast #><#= item.Name #>, name);
|
||||
}
|
||||
<#
|
||||
});
|
||||
});
|
||||
#>
|
||||
}
|
||||
|
||||
@@ -10,19 +10,19 @@ namespace PerformanceFish.Utility.Diagnostics;
|
||||
partial class Guard
|
||||
{
|
||||
<#
|
||||
GenerateTextForItems(NumericTypes, typeInfo =>
|
||||
{
|
||||
var (type, prefix) = typeInfo;
|
||||
GenerateTextForItems(NumericTypes, typeInfo =>
|
||||
{
|
||||
var (type, prefix) = typeInfo;
|
||||
#>
|
||||
/// <summary>
|
||||
/// Asserts that the input value must be equal to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="target">The target <see <#=prefix#>="<#=type#>"/> value to test for.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="target">The target <see <#= prefix #>="<#= type #>"/> value to test for.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is != <paramref name="target"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsEqualTo(<#=type#> value, <#=type#> target, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsEqualTo(<#= type #> value, <#= type #> target, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value == target)
|
||||
{
|
||||
@@ -35,13 +35,13 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must be not equal to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="target">The target <see <#=prefix#>="<#=type#>"/> value to test for.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="target">The target <see <#= prefix #>="<#= type #>"/> value to test for.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is == <paramref name="target"/>.</exception>
|
||||
/// <remarks>The method is generic to avoid boxing the parameters, if they are value types.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotEqualTo(<#=type#> value, <#=type#> target, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotEqualTo(<#= type #> value, <#= type #> target, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value != target)
|
||||
{
|
||||
@@ -54,13 +54,13 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must be less than a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="maximum">The exclusive maximum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="maximum">The exclusive maximum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is >= <paramref name="maximum"/>.</exception>
|
||||
/// <remarks>The method is generic to avoid boxing the parameters, if they are value types.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsLessThan(<#=type#> value, <#=type#> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsLessThan(<#= type #> value, <#= type #> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value < maximum)
|
||||
{
|
||||
@@ -73,13 +73,13 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must be less than or equal to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="maximum">The inclusive maximum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="maximum">The inclusive maximum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is > <paramref name="maximum"/>.</exception>
|
||||
/// <remarks>The method is generic to avoid boxing the parameters, if they are value types.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsLessThanOrEqualTo(<#=type#> value, <#=type#> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsLessThanOrEqualTo(<#= type #> value, <#= type #> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value <= maximum)
|
||||
{
|
||||
@@ -92,13 +92,13 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must be greater than a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="minimum">The exclusive minimum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="minimum">The exclusive minimum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is <= <paramref name="minimum"/>.</exception>
|
||||
/// <remarks>The method is generic to avoid boxing the parameters, if they are value types.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsGreaterThan(<#=type#> value, <#=type#> minimum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsGreaterThan(<#= type #> value, <#= type #> minimum, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value > minimum)
|
||||
{
|
||||
@@ -111,13 +111,13 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must be greater than or equal to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="minimum">The inclusive minimum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="minimum">The inclusive minimum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is < <paramref name="minimum"/>.</exception>
|
||||
/// <remarks>The method is generic to avoid boxing the parameters, if they are value types.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsGreaterThanOrEqualTo(<#=type#> value, <#=type#> minimum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsGreaterThanOrEqualTo(<#= type #> value, <#= type #> minimum, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value >= minimum)
|
||||
{
|
||||
@@ -130,9 +130,9 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must be in a given range.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="minimum">The inclusive minimum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The exclusive maximum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="minimum">The inclusive minimum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The exclusive maximum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is < <paramref name="minimum"/> or >= <paramref name="maximum"/>.</exception>
|
||||
/// <remarks>
|
||||
@@ -140,7 +140,7 @@ var (type, prefix) = typeInfo;
|
||||
/// The method is generic to avoid boxing the parameters, if they are value types.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsInRange(<#=type#> value, <#=type#> minimum, <#=type#> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsInRange(<#= type #> value, <#= type #> minimum, <#= type #> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value >= minimum && value < maximum)
|
||||
{
|
||||
@@ -153,9 +153,9 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must not be in a given range.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="minimum">The inclusive minimum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The exclusive maximum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="minimum">The inclusive minimum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The exclusive maximum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is >= <paramref name="minimum"/> or < <paramref name="maximum"/>.</exception>
|
||||
/// <remarks>
|
||||
@@ -163,7 +163,7 @@ var (type, prefix) = typeInfo;
|
||||
/// The method is generic to avoid boxing the parameters, if they are value types.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotInRange(<#=type#> value, <#=type#> minimum, <#=type#> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotInRange(<#= type #> value, <#= type #> minimum, <#= type #> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value < minimum || value >= maximum)
|
||||
{
|
||||
@@ -176,9 +176,9 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must be in a given interval.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="minimum">The exclusive minimum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The exclusive maximum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="minimum">The exclusive minimum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The exclusive maximum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is <= <paramref name="minimum"/> or >= <paramref name="maximum"/>.</exception>
|
||||
/// <remarks>
|
||||
@@ -186,7 +186,7 @@ var (type, prefix) = typeInfo;
|
||||
/// The method is generic to avoid boxing the parameters, if they are value types.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsBetween(<#=type#> value, <#=type#> minimum, <#=type#> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsBetween(<#= type #> value, <#= type #> minimum, <#= type #> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value > minimum && value < maximum)
|
||||
{
|
||||
@@ -199,9 +199,9 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must not be in a given interval.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="minimum">The exclusive minimum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The exclusive maximum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="minimum">The exclusive minimum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The exclusive maximum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is > <paramref name="minimum"/> or < <paramref name="maximum"/>.</exception>
|
||||
/// <remarks>
|
||||
@@ -209,7 +209,7 @@ var (type, prefix) = typeInfo;
|
||||
/// The method is generic to avoid boxing the parameters, if they are value types.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotBetween(<#=type#> value, <#=type#> minimum, <#=type#> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotBetween(<#= type #> value, <#= type #> minimum, <#= type #> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value <= minimum || value >= maximum)
|
||||
{
|
||||
@@ -222,9 +222,9 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must be in a given interval.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="minimum">The inclusive minimum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The inclusive maximum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="minimum">The inclusive minimum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The inclusive maximum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is < <paramref name="minimum"/> or > <paramref name="maximum"/>.</exception>
|
||||
/// <remarks>
|
||||
@@ -232,7 +232,7 @@ var (type, prefix) = typeInfo;
|
||||
/// The method is generic to avoid boxing the parameters, if they are value types.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsBetweenOrEqualTo(<#=type#> value, <#=type#> minimum, <#=type#> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsBetweenOrEqualTo(<#= type #> value, <#= type #> minimum, <#= type #> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value >= minimum && value <= maximum)
|
||||
{
|
||||
@@ -245,9 +245,9 @@ var (type, prefix) = typeInfo;
|
||||
/// <summary>
|
||||
/// Asserts that the input value must not be in a given interval.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see <#=prefix#>="<#=type#>"/> value to test.</param>
|
||||
/// <param name="minimum">The inclusive minimum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The inclusive maximum <see <#=prefix#>="<#=type#>"/> value that is accepted.</param>
|
||||
/// <param name="value">The input <see <#= prefix #>="<#= type #>"/> value to test.</param>
|
||||
/// <param name="minimum">The inclusive minimum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="maximum">The inclusive maximum <see <#= prefix #>="<#= type #>"/> value that is accepted.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is >= <paramref name="minimum"/> or <= <paramref name="maximum"/>.</exception>
|
||||
/// <remarks>
|
||||
@@ -255,7 +255,7 @@ var (type, prefix) = typeInfo;
|
||||
/// The method is generic to avoid boxing the parameters, if they are value types.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotBetweenOrEqualTo(<#=type#> value, <#=type#> minimum, <#=type#> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotBetweenOrEqualTo(<#= type #> value, <#= type #> minimum, <#= type #> maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value < minimum || value > maximum)
|
||||
{
|
||||
@@ -265,6 +265,6 @@ var (type, prefix) = typeInfo;
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(value, minimum, maximum, name);
|
||||
}
|
||||
<#
|
||||
});
|
||||
});
|
||||
#>
|
||||
}
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
# T4 templates and generated APIs
|
||||
|
||||
This folder contains a number of template files (with the `.tt` or `.ttinclude` extensions) and the generated `.g.cs` files generated by those templates. The template files use the T4 format, which is natively supported by Visual Studio (more info is available [here](https://docs.microsoft.com/visualstudio/modeling/code-generation-and-t4-text-templates)).
|
||||
This folder contains a number of template files (with the `.tt` or `.ttinclude` extensions) and the generated `.g.cs`
|
||||
files generated by those templates. The template files use the T4 format, which is natively supported by Visual Studio (
|
||||
more info is available [here](https://docs.microsoft.com/visualstudio/modeling/code-generation-and-t4-text-templates)).
|
||||
|
||||
## Why is this needed?
|
||||
|
||||
There are a few reasons why T4 templates are used for the `Guard` class:
|
||||
|
||||
- Especially when many overloads are available for an API, using templates makes it much easier to maintain code and spot mistakes, as the actual number of lines of code to review is much smaller: it's just the same code from each template!
|
||||
- Using type-specific overloads instead of generic methods can result in faster code. For instance, T4 templates are used to generate overloads for comparison APIs (eg. `Guard.IsGreaterThan(int, int, string)`). This results in more compact and optimized code as opposed to a generic method using `where T : IComparable<T>` as type constraint.
|
||||
- In some cases, using generic methods just isn't possible. For instance, types like `Span<T>` and `ReadOnlySpan<T>` can't be used as generic type parameters, and even if that had been possible, they don't implement an interface we could use in the generic type constraint. Using T4 templates solves this issue, as we can just have specialized method for each supported type or collection type.
|
||||
- Especially when many overloads are available for an API, using templates makes it much easier to maintain code and
|
||||
spot mistakes, as the actual number of lines of code to review is much smaller: it's just the same code from each
|
||||
template!
|
||||
- Using type-specific overloads instead of generic methods can result in faster code. For instance, T4 templates are
|
||||
used to generate overloads for comparison APIs (eg. `Guard.IsGreaterThan(int, int, string)`). This results in more
|
||||
compact and optimized code as opposed to a generic method using `where T : IComparable<T>` as type constraint.
|
||||
- In some cases, using generic methods just isn't possible. For instance, types like `Span<T>` and `ReadOnlySpan<T>`
|
||||
can't be used as generic type parameters, and even if that had been possible, they don't implement an interface we
|
||||
could use in the generic type constraint. Using T4 templates solves this issue, as we can just have specialized method
|
||||
for each supported type or collection type.
|
||||
|
||||
## How to make changes
|
||||
|
||||
If you need to change an API that is declared in a template, or to add a new one, just edit the right `.tt` file and save it: Visual Studio will take care of updating the generated `.g.cs` file automatically. Don't make changes to those generated `.g.cs` files directly, as those will be overwritten as soon as their source template is updated.
|
||||
If you need to change an API that is declared in a template, or to add a new one, just edit the right `.tt` file and
|
||||
save it: Visual Studio will take care of updating the generated `.g.cs` file automatically. Don't make changes to those
|
||||
generated `.g.cs` files directly, as those will be overwritten as soon as their source template is updated.
|
||||
|
||||
Note that all the `.g.cs` files are checked in into the repository, so if you do make changes to a template file, make sure to also include the updated `.g.cs` file in your commits.
|
||||
Note that all the `.g.cs` files are checked in into the repository, so if you do make changes to a template file, make
|
||||
sure to also include the updated `.g.cs` file in your commits.
|
||||
|
||||
@@ -13,109 +13,109 @@ partial class Guard
|
||||
partial class ThrowHelper
|
||||
{
|
||||
<#
|
||||
GenerateTextForItems(EnumerableTypes, item =>
|
||||
{
|
||||
GenerateTextForItems(EnumerableTypes, item =>
|
||||
{
|
||||
#>
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsEmpty{T}(T[],string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(<#=item.Type#> <#=item.Name#>, string name)
|
||||
public static void ThrowArgumentExceptionForIsEmpty<T>(<#= item.Type #> <#= item.Name #>, string name)
|
||||
{
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#= item.Type #>).ToTypeString()}) must be empty, had a size of {AssertString(<#= item.Name #>.<#= item.Size #>)}.", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#= item.Type #> <#= item.Name #>, int size, string name)
|
||||
{
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#= item.Type #>).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(<#= item.Name #>.<#= item.Size #>)}.", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(<#= item.Type #> <#= item.Name #>, int size, string name)
|
||||
{
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#= item.Type #>).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(<#= item.Name #>.<#= item.Size #>)}.", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(<#= item.Type #> <#= item.Name #>, int size, string name)
|
||||
{
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#= item.Type #>).ToTypeString()}) must have a size over {size}, had a size of {AssertString(<#= item.Name #>.<#= item.Size #>)}.", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(<#= item.Type #> <#= item.Name #>, int size, string name)
|
||||
{
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#= item.Type #>).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(<#= item.Name #>.<#= item.Size #>)}.", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(<#= item.Type #> <#= item.Name #>, int size, string name)
|
||||
{
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#= item.Type #>).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(<#= item.Name #>.<#= item.Size #>)}.", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#= item.Type #> <#= item.Name #>, int size, string name)
|
||||
{
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#= item.Type #>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(<#= item.Name #>.<#= item.Size #>)}.", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#= item.Type #> source, <#= item.DestinationType #> destination, string name)
|
||||
{
|
||||
throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}.", name);
|
||||
throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#= item.Type #>).ToTypeString()}) must have a size equal to {AssertString(destination.<#= item.Size #>)} (the destination), had a size of {AssertString(source.<#= item.Size #>)}.", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#= item.Type #> source, <#= item.DestinationType #> destination, string name)
|
||||
{
|
||||
throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}.", name);
|
||||
throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#= item.Type #>).ToTypeString()}) must have a size less than or equal to {AssertString(destination.<#= item.Size #>)} (the destination), had a size of {AssertString(source.<#= item.Size #>)}.", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, <#= item.Type #> <#= item.Name #>, string name)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}.");
|
||||
throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(<#= item.Name #>.<#= item.Size #>)} to be a valid index for the target collection ({typeof(<#= item.Type #>).ToTypeString()}), was {AssertString(index)}.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, <#= item.Type #> <#= item.Name #>, string name)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}.");
|
||||
throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(<#= item.Name #>.<#= item.Size #>)} to be an invalid index for the target collection ({typeof(<#= item.Type #>).ToTypeString()}), was {AssertString(index)}.");
|
||||
}
|
||||
<#
|
||||
});
|
||||
});
|
||||
#>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,11 +71,14 @@
|
||||
new EnumerableTypeInfo("Span<T>", "<see cref=\"Span{T}\"/>", "span", "Length", "Span<T>", ""),
|
||||
new EnumerableTypeInfo("ReadOnlySpan<T>", "<see cref=\"ReadOnlySpan{T}\"/>", "span", "Length", "Span<T>", ""),
|
||||
new EnumerableTypeInfo("Memory<T>", "<see cref=\"Memory{T}\"/>", "memory", "Length", "Memory<T>", ""),
|
||||
new EnumerableTypeInfo("ReadOnlyMemory<T>", "<see cref=\"ReadOnlyMemory{T}\"/>", "memory", "Length", "Memory<T>", ""),
|
||||
new EnumerableTypeInfo("ReadOnlyMemory<T>", "<see cref=\"ReadOnlyMemory{T}\"/>", "memory", "Length", "Memory<T>",
|
||||
""),
|
||||
new EnumerableTypeInfo("T[]", "<see typeparamref=\"T\"/> array", "array", "Length", "T[]", ""),
|
||||
new EnumerableTypeInfo("List<T>", "<see cref=\"List{T}\"/>", "list", "Count", "List<T>", "(ICollection<T>)"),
|
||||
new EnumerableTypeInfo("ICollection<T>", "<see cref=\"ICollection{T}\"/>", "collection", "Count", "ICollection<T>", ""),
|
||||
new EnumerableTypeInfo("IReadOnlyCollection<T>", "<see cref=\"IReadOnlyCollection{T}\"/>", "collection", "Count", "ICollection<T>", ""),
|
||||
new EnumerableTypeInfo("ICollection<T>", "<see cref=\"ICollection{T}\"/>", "collection", "Count",
|
||||
"ICollection<T>", ""),
|
||||
new EnumerableTypeInfo("IReadOnlyCollection<T>", "<see cref=\"IReadOnlyCollection{T}\"/>", "collection", "Count",
|
||||
"ICollection<T>", "")
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -107,10 +110,11 @@
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
// Insert a blank line after the first item
|
||||
if (i > 0) WriteLine("");
|
||||
if (i > 0)
|
||||
WriteLine("");
|
||||
|
||||
// Invoke the factory with the current item
|
||||
factory(items [i]);
|
||||
factory(items[i]);
|
||||
}
|
||||
}
|
||||
#>
|
||||
@@ -20,9 +20,7 @@ public static partial class Guard
|
||||
public static void IsTrue([DoesNotReturnIf(false)] bool value, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsTrue(name);
|
||||
}
|
||||
@@ -38,9 +36,7 @@ public static partial class Guard
|
||||
public static void IsTrue([DoesNotReturnIf(false)] bool value, string name, string message)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsTrue(name, message);
|
||||
}
|
||||
@@ -55,9 +51,7 @@ public static partial class Guard
|
||||
public static void IsFalse([DoesNotReturnIf(true)] bool value, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsFalse(name);
|
||||
}
|
||||
@@ -73,9 +67,7 @@ public static partial class Guard
|
||||
public static void IsFalse([DoesNotReturnIf(true)] bool value, string name, string message)
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsFalse(name, message);
|
||||
}
|
||||
@@ -155,7 +147,8 @@ public static partial class Guard
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
|
||||
this.handler = new StringBuilder.AppendInterpolatedStringHandler(literalLength, formattedCount, builder);
|
||||
this.handler =
|
||||
new StringBuilder.AppendInterpolatedStringHandler(literalLength, formattedCount, builder);
|
||||
this.builder = builder;
|
||||
|
||||
shouldAppend = true;
|
||||
@@ -273,7 +266,8 @@ public static partial class Guard
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
|
||||
this.handler = new StringBuilder.AppendInterpolatedStringHandler(literalLength, formattedCount, builder);
|
||||
this.handler =
|
||||
new StringBuilder.AppendInterpolatedStringHandler(literalLength, formattedCount, builder);
|
||||
this.builder = builder;
|
||||
|
||||
shouldAppend = true;
|
||||
@@ -353,4 +347,4 @@ public static partial class Guard
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,7 @@ public partial class Guard
|
||||
where T : struct, IEquatable<T>
|
||||
{
|
||||
if (value.Equals(default))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsDefault(value, name);
|
||||
}
|
||||
@@ -40,9 +38,7 @@ public partial class Guard
|
||||
where T : struct, IEquatable<T>
|
||||
{
|
||||
if (!value.Equals(default))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotDefault<T>(name);
|
||||
}
|
||||
@@ -61,9 +57,7 @@ public partial class Guard
|
||||
where T : notnull, IEquatable<T>
|
||||
{
|
||||
if (value.Equals(target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsEqualTo(value, target, name);
|
||||
}
|
||||
@@ -82,9 +76,7 @@ public partial class Guard
|
||||
where T : notnull, IEquatable<T>
|
||||
{
|
||||
if (!value.Equals(target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotEqualTo(value, target, name);
|
||||
}
|
||||
@@ -98,7 +90,8 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is not a bitwise match for <paramref name="target"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void IsBitwiseEqualTo<T>(T value, T target, [CallerArgumentExpression("value")] string name = "")
|
||||
public static unsafe void IsBitwiseEqualTo<T>(T value, T target,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
where T : unmanaged
|
||||
{
|
||||
// Include some fast paths if the input type is of size 1, 2, 4, 8, or 16.
|
||||
@@ -112,9 +105,7 @@ public partial class Guard
|
||||
var targetByte = Unsafe.As<T, byte>(ref target);
|
||||
|
||||
if (valueByte == targetByte)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForBitwiseEqualTo(value, target, name);
|
||||
}
|
||||
@@ -124,9 +115,7 @@ public partial class Guard
|
||||
var targetUShort = Unsafe.As<T, ushort>(ref target);
|
||||
|
||||
if (valueUShort == targetUShort)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForBitwiseEqualTo(value, target, name);
|
||||
}
|
||||
@@ -136,9 +125,7 @@ public partial class Guard
|
||||
var targetUInt = Unsafe.As<T, uint>(ref target);
|
||||
|
||||
if (valueUInt == targetUInt)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForBitwiseEqualTo(value, target, name);
|
||||
}
|
||||
@@ -148,9 +135,7 @@ public partial class Guard
|
||||
var targetULong = Unsafe.As<T, ulong>(ref target);
|
||||
|
||||
if (Bit64Compare(ref valueULong, ref targetULong))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForBitwiseEqualTo(value, target, name);
|
||||
}
|
||||
@@ -165,9 +150,7 @@ public partial class Guard
|
||||
var targetULong1 = Unsafe.Add(ref Unsafe.As<T, ulong>(ref target), 1);
|
||||
|
||||
if (Bit64Compare(ref valueULong1, ref targetULong1))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForBitwiseEqualTo(value, target, name);
|
||||
@@ -178,9 +161,7 @@ public partial class Guard
|
||||
Span<byte> targetBytes = new(Unsafe.AsPointer(ref target), sizeof(T));
|
||||
|
||||
if (valueBytes.SequenceEqual(targetBytes))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForBitwiseEqualTo(value, target, name);
|
||||
}
|
||||
@@ -196,8 +177,7 @@ public partial class Guard
|
||||
ref var r0 = ref Unsafe.As<ulong, int>(ref left);
|
||||
ref var r1 = ref Unsafe.As<ulong, int>(ref right);
|
||||
|
||||
return r0 == r1 &&
|
||||
Unsafe.Add(ref r0, 1) == Unsafe.Add(ref r1, 1);
|
||||
return r0 == r1 && Unsafe.Add(ref r0, 1) == Unsafe.Add(ref r1, 1);
|
||||
}
|
||||
|
||||
return left == right;
|
||||
@@ -217,9 +197,7 @@ public partial class Guard
|
||||
where T : notnull, IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(maximum) < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsLessThan(value, maximum, name);
|
||||
}
|
||||
@@ -238,9 +216,7 @@ public partial class Guard
|
||||
where T : notnull, IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(maximum) <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(value, maximum, name);
|
||||
}
|
||||
@@ -259,9 +235,7 @@ public partial class Guard
|
||||
where T : notnull, IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(minimum) > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsGreaterThan(value, minimum, name);
|
||||
}
|
||||
@@ -276,13 +250,12 @@ public partial class Guard
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is < <paramref name="minimum"/>.</exception>
|
||||
/// <remarks>The method is generic to avoid boxing the parameters, if they are value types.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsGreaterThanOrEqualTo<T>(T value, T minimum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsGreaterThanOrEqualTo<T>(T value, T minimum,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
where T : notnull, IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(minimum) >= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(value, minimum, name);
|
||||
}
|
||||
@@ -305,9 +278,7 @@ public partial class Guard
|
||||
where T : notnull, IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(minimum) >= 0 && value.CompareTo(maximum) < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRange(value, minimum, maximum, name);
|
||||
}
|
||||
@@ -326,13 +297,12 @@ public partial class Guard
|
||||
/// The method is generic to avoid boxing the parameters, if they are value types.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotInRange<T>(T value, T minimum, T maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotInRange<T>(T value, T minimum, T maximum,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
where T : notnull, IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(minimum) < 0 || value.CompareTo(maximum) >= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRange(value, minimum, maximum, name);
|
||||
}
|
||||
@@ -355,9 +325,7 @@ public partial class Guard
|
||||
where T : notnull, IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(minimum) > 0 && value.CompareTo(maximum) < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsBetween(value, minimum, maximum, name);
|
||||
}
|
||||
@@ -376,13 +344,12 @@ public partial class Guard
|
||||
/// The method is generic to avoid boxing the parameters, if they are value types.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotBetween<T>(T value, T minimum, T maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotBetween<T>(T value, T minimum, T maximum,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
where T : notnull, IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(minimum) <= 0 || value.CompareTo(maximum) >= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotBetween(value, minimum, maximum, name);
|
||||
}
|
||||
@@ -401,13 +368,12 @@ public partial class Guard
|
||||
/// The method is generic to avoid boxing the parameters, if they are value types.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsBetweenOrEqualTo<T>(T value, T minimum, T maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsBetweenOrEqualTo<T>(T value, T minimum, T maximum,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
where T : notnull, IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(minimum) >= 0 && value.CompareTo(maximum) <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(value, minimum, maximum, name);
|
||||
}
|
||||
@@ -426,14 +392,13 @@ public partial class Guard
|
||||
/// The method is generic to avoid boxing the parameters, if they are value types.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotBetweenOrEqualTo<T>(T value, T minimum, T maximum, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotBetweenOrEqualTo<T>(T value, T minimum, T maximum,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
where T : notnull, IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(minimum) < 0 || value.CompareTo(maximum) > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(value, minimum, maximum, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,14 +18,13 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if (<paramref name="value"/> - <paramref name="target"/>) > <paramref name="delta"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsCloseTo(int value, int target, uint delta, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsCloseTo(int value, int target, uint delta,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
var difference = value >= target ? (uint)(value - target) : (uint)(target - value);
|
||||
|
||||
if (difference <= delta)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsCloseTo(value, target, delta, name);
|
||||
}
|
||||
@@ -39,14 +38,13 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if (<paramref name="value"/> - <paramref name="target"/>) <= <paramref name="delta"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotCloseTo(int value, int target, uint delta, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotCloseTo(int value, int target, uint delta,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
var difference = value >= target ? (uint)(value - target) : (uint)(target - value);
|
||||
|
||||
if (difference > delta)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotCloseTo(value, target, delta, name);
|
||||
}
|
||||
@@ -60,14 +58,13 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if (<paramref name="value"/> - <paramref name="target"/>) > <paramref name="delta"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsCloseTo(long value, long target, ulong delta, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsCloseTo(long value, long target, ulong delta,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
var difference = value >= target ? (ulong)(value - target) : (ulong)(target - value);
|
||||
|
||||
if (difference <= delta)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsCloseTo(value, target, delta, name);
|
||||
}
|
||||
@@ -81,14 +78,13 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if (<paramref name="value"/> - <paramref name="target"/>) <= <paramref name="delta"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotCloseTo(long value, long target, ulong delta, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotCloseTo(long value, long target, ulong delta,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
var difference = value >= target ? (ulong)(value - target) : (ulong)(target - value);
|
||||
|
||||
if (difference > delta)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotCloseTo(value, target, delta, name);
|
||||
}
|
||||
@@ -102,12 +98,11 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if (<paramref name="value"/> - <paramref name="target"/>) > <paramref name="delta"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsCloseTo(float value, float target, float delta, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsCloseTo(float value, float target, float delta,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (Math.Abs(value - target) <= delta)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsCloseTo(value, target, delta, name);
|
||||
}
|
||||
@@ -121,12 +116,11 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if (<paramref name="value"/> - <paramref name="target"/>) <= <paramref name="delta"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotCloseTo(float value, float target, float delta, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotCloseTo(float value, float target, float delta,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (Math.Abs(value - target) > delta)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotCloseTo(value, target, delta, name);
|
||||
}
|
||||
@@ -140,12 +134,11 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if (<paramref name="value"/> - <paramref name="target"/>) > <paramref name="delta"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsCloseTo(double value, double target, double delta, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsCloseTo(double value, double target, double delta,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (Math.Abs(value - target) <= delta)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsCloseTo(value, target, delta, name);
|
||||
}
|
||||
@@ -159,12 +152,11 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if (<paramref name="value"/> - <paramref name="target"/>) <= <paramref name="delta"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotCloseTo(double value, double target, double delta, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotCloseTo(double value, double target, double delta,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (Math.Abs(value - target) > delta)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotCloseTo(value, target, delta, name);
|
||||
}
|
||||
@@ -178,14 +170,13 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if (<paramref name="value"/> - <paramref name="target"/>) > <paramref name="delta"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsCloseTo(nint value, nint target, nuint delta, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsCloseTo(nint value, nint target, nuint delta,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
var difference = value >= target ? (nuint)(value - target) : (nuint)(target - value);
|
||||
|
||||
if (difference <= delta)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsCloseTo(value, target, delta, name);
|
||||
}
|
||||
@@ -199,15 +190,14 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if (<paramref name="value"/> - <paramref name="target"/>) <= <paramref name="delta"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotCloseTo(nint value, nint target, nuint delta, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotCloseTo(nint value, nint target, nuint delta,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
var difference = value >= target ? (nuint)(value - target) : (nuint)(target - value);
|
||||
|
||||
if (difference > delta)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotCloseTo(value, target, delta, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,7 @@ public partial class Guard
|
||||
public static void CanRead(Stream stream, [CallerArgumentExpression("stream")] string name = "")
|
||||
{
|
||||
if (stream.CanRead)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForCanRead(stream, name);
|
||||
}
|
||||
@@ -37,9 +35,7 @@ public partial class Guard
|
||||
public static void CanWrite(Stream stream, [CallerArgumentExpression("stream")] string name = "")
|
||||
{
|
||||
if (stream.CanWrite)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForCanWrite(stream, name);
|
||||
}
|
||||
@@ -54,9 +50,7 @@ public partial class Guard
|
||||
public static void CanSeek(Stream stream, [CallerArgumentExpression("stream")] string name = "")
|
||||
{
|
||||
if (stream.CanSeek)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForCanSeek(stream, name);
|
||||
}
|
||||
@@ -71,10 +65,8 @@ public partial class Guard
|
||||
public static void IsAtStartPosition(Stream stream, [CallerArgumentExpression("stream")] string name = "")
|
||||
{
|
||||
if (stream.Position == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsAtStartPosition(stream, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,7 @@ public partial class Guard
|
||||
public static void IsNullOrEmpty(string? text, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNullOrEmpty(text, name);
|
||||
}
|
||||
@@ -40,9 +38,7 @@ public partial class Guard
|
||||
public static void IsNotNullOrEmpty([NotNull] string? text, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotNullOrEmpty(text, name);
|
||||
}
|
||||
@@ -57,9 +53,7 @@ public partial class Guard
|
||||
public static void IsNullOrWhiteSpace(string? text, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNullOrWhiteSpace(text, name);
|
||||
}
|
||||
@@ -72,12 +66,11 @@ public partial class Guard
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="text"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is whitespace.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotNullOrWhiteSpace([NotNull] string? text, [CallerArgumentExpression("text")] string name = "")
|
||||
public static void IsNotNullOrWhiteSpace([NotNull] string? text,
|
||||
[CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotNullOrWhiteSpace(text, name);
|
||||
}
|
||||
@@ -92,9 +85,7 @@ public partial class Guard
|
||||
public static void IsEmpty(string text, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (text.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsEmpty(text, name);
|
||||
}
|
||||
@@ -109,9 +100,7 @@ public partial class Guard
|
||||
public static void IsNotEmpty(string text, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (text.Length != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotEmpty(name);
|
||||
}
|
||||
@@ -126,9 +115,7 @@ public partial class Guard
|
||||
public static void IsWhiteSpace(string text, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsWhiteSpace(text, name);
|
||||
}
|
||||
@@ -143,9 +130,7 @@ public partial class Guard
|
||||
public static void IsNotWhiteSpace(string text, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotWhiteSpace(text, name);
|
||||
}
|
||||
@@ -161,9 +146,7 @@ public partial class Guard
|
||||
public static void HasSizeEqualTo(string text, int size, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (text.Length == size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(text, size, name);
|
||||
}
|
||||
@@ -179,9 +162,7 @@ public partial class Guard
|
||||
public static void HasSizeNotEqualTo(string text, int size, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (text.Length != size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeNotEqualTo(text, size, name);
|
||||
}
|
||||
@@ -197,9 +178,7 @@ public partial class Guard
|
||||
public static void HasSizeGreaterThan(string text, int size, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (text.Length > size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(text, size, name);
|
||||
}
|
||||
@@ -212,12 +191,11 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="text"/> is < <paramref name="size"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeGreaterThanOrEqualTo(string text, int size, [CallerArgumentExpression("text")] string name = "")
|
||||
public static void HasSizeGreaterThanOrEqualTo(string text, int size,
|
||||
[CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (text.Length >= size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(text, size, name);
|
||||
}
|
||||
@@ -233,9 +211,7 @@ public partial class Guard
|
||||
public static void HasSizeLessThan(string text, int size, [CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (text.Length < size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThan(text, size, name);
|
||||
}
|
||||
@@ -248,12 +224,11 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="text"/> is > <paramref name="size"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeLessThanOrEqualTo(string text, int size, [CallerArgumentExpression("text")] string name = "")
|
||||
public static void HasSizeLessThanOrEqualTo(string text, int size,
|
||||
[CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (text.Length <= size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(text, size, name);
|
||||
}
|
||||
@@ -267,12 +242,11 @@ public partial class Guard
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="text"/> is != the one of <paramref name="destination"/>.</exception>
|
||||
/// <remarks>The <see cref="string"/> type is immutable, but the name of this API is kept for consistency with the other overloads.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeEqualTo(string text, string destination, [CallerArgumentExpression("text")] string name = "")
|
||||
public static void HasSizeEqualTo(string text, string destination,
|
||||
[CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (text.Length == destination.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(text, destination, name);
|
||||
}
|
||||
@@ -286,12 +260,11 @@ public partial class Guard
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="text"/> is > the one of <paramref name="destination"/>.</exception>
|
||||
/// <remarks>The <see cref="string"/> type is immutable, but the name of this API is kept for consistency with the other overloads.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasSizeLessThanOrEqualTo(string text, string destination, [CallerArgumentExpression("text")] string name = "")
|
||||
public static void HasSizeLessThanOrEqualTo(string text, string destination,
|
||||
[CallerArgumentExpression("text")] string name = "")
|
||||
{
|
||||
if (text.Length <= destination.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(text, destination, name);
|
||||
}
|
||||
@@ -307,9 +280,7 @@ public partial class Guard
|
||||
public static void IsInRangeFor(int index, string text, [CallerArgumentExpression("index")] string name = "")
|
||||
{
|
||||
if ((uint)index < (uint)text.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRangeFor(index, text, name);
|
||||
}
|
||||
@@ -325,10 +296,8 @@ public partial class Guard
|
||||
public static void IsNotInRangeFor(int index, string text, [CallerArgumentExpression("index")] string name = "")
|
||||
{
|
||||
if ((uint)index >= (uint)text.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(index, text, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,7 @@ public partial class Guard
|
||||
public static void IsCompleted(Task task, [CallerArgumentExpression("task")] string name = "")
|
||||
{
|
||||
if (task.IsCompleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsCompleted(task, name);
|
||||
}
|
||||
@@ -37,9 +35,7 @@ public partial class Guard
|
||||
public static void IsNotCompleted(Task task, [CallerArgumentExpression("task")] string name = "")
|
||||
{
|
||||
if (!task.IsCompleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotCompleted(task, name);
|
||||
}
|
||||
@@ -54,9 +50,7 @@ public partial class Guard
|
||||
public static void IsCompletedSuccessfully(Task task, [CallerArgumentExpression("task")] string name = "")
|
||||
{
|
||||
if (task.Status == TaskStatus.RanToCompletion)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsCompletedSuccessfully(task, name);
|
||||
}
|
||||
@@ -71,9 +65,7 @@ public partial class Guard
|
||||
public static void IsNotCompletedSuccessfully(Task task, [CallerArgumentExpression("task")] string name = "")
|
||||
{
|
||||
if (task.Status != TaskStatus.RanToCompletion)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotCompletedSuccessfully(task, name);
|
||||
}
|
||||
@@ -88,9 +80,7 @@ public partial class Guard
|
||||
public static void IsFaulted(Task task, [CallerArgumentExpression("task")] string name = "")
|
||||
{
|
||||
if (task.IsFaulted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsFaulted(task, name);
|
||||
}
|
||||
@@ -105,9 +95,7 @@ public partial class Guard
|
||||
public static void IsNotFaulted(Task task, [CallerArgumentExpression("task")] string name = "")
|
||||
{
|
||||
if (!task.IsFaulted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotFaulted(task, name);
|
||||
}
|
||||
@@ -122,9 +110,7 @@ public partial class Guard
|
||||
public static void IsCanceled(Task task, [CallerArgumentExpression("task")] string name = "")
|
||||
{
|
||||
if (task.IsCanceled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsCanceled(task, name);
|
||||
}
|
||||
@@ -139,9 +125,7 @@ public partial class Guard
|
||||
public static void IsNotCanceled(Task task, [CallerArgumentExpression("task")] string name = "")
|
||||
{
|
||||
if (!task.IsCanceled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotCanceled(task, name);
|
||||
}
|
||||
@@ -154,12 +138,11 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="task"/> doesn't match <paramref name="status"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasStatusEqualTo(Task task, TaskStatus status, [CallerArgumentExpression("task")] string name = "")
|
||||
public static void HasStatusEqualTo(Task task, TaskStatus status,
|
||||
[CallerArgumentExpression("task")] string name = "")
|
||||
{
|
||||
if (task.Status == status)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasStatusEqualTo(task, status, name);
|
||||
}
|
||||
@@ -172,13 +155,12 @@ public partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="task"/> matches <paramref name="status"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void HasStatusNotEqualTo(Task task, TaskStatus status, [CallerArgumentExpression("task")] string name = "")
|
||||
public static void HasStatusNotEqualTo(Task task, TaskStatus status,
|
||||
[CallerArgumentExpression("task")] string name = "")
|
||||
{
|
||||
if (task.Status != status)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForHasStatusNotEqualTo(task, status, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,9 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using JetBrains.Annotations;
|
||||
using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute;
|
||||
|
||||
namespace FisheryLib.Utility.Diagnostics;
|
||||
|
||||
@@ -12,6 +13,7 @@ namespace FisheryLib.Utility.Diagnostics;
|
||||
/// Helper methods to verify conditions when running code.
|
||||
/// </summary>
|
||||
[DebuggerStepThrough]
|
||||
[PublicAPI]
|
||||
public static partial class Guard
|
||||
{
|
||||
/// <summary>
|
||||
@@ -22,7 +24,7 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is not <see langword="null"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNull<T>(T? value, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNull<T>([NoEnumeration] T? value, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value is null)
|
||||
return;
|
||||
@@ -38,7 +40,7 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is not <see langword="null"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNull<T>(T? value, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNull<T>([NoEnumeration] T? value, [CallerArgumentExpression("value")] string name = "")
|
||||
where T : struct
|
||||
{
|
||||
if (value is null)
|
||||
@@ -55,7 +57,8 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <see langword="null"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotNull<T>([NotNull] T? value, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotNull<T>([NoEnumeration] [NotNull] T? value,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value is not null)
|
||||
return;
|
||||
@@ -71,7 +74,8 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <see langword="null"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotNull<T>([NotNull] T? value, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotNull<T>([NoEnumeration] [NotNull] T? value,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
where T : struct
|
||||
{
|
||||
if (value is not null)
|
||||
@@ -88,7 +92,7 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is not of type <typeparamref name="T"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsOfType<T>(object value, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsOfType<T>([NoEnumeration] object value, [CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value.GetType() == typeof(T))
|
||||
return;
|
||||
@@ -104,7 +108,8 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is of type <typeparamref name="T"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotOfType<T>(object value, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotOfType<T>([NoEnumeration] object value,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value.GetType() != typeof(T))
|
||||
return;
|
||||
@@ -120,7 +125,8 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the type of <paramref name="value"/> is not the same as <paramref name="type"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsOfType(object value, Type type, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsOfType([NoEnumeration] object value, Type type,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value.GetType() == type)
|
||||
return;
|
||||
@@ -136,7 +142,8 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the type of <paramref name="value"/> is the same as <paramref name="type"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotOfType(object value, Type type, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotOfType([NoEnumeration] object value, Type type,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value.GetType() != type)
|
||||
return;
|
||||
@@ -152,7 +159,8 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> can't be assigned to type <typeparamref name="T"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsAssignableToType<T>(object value, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsAssignableToType<T>([NoEnumeration] object value,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value is T)
|
||||
return;
|
||||
@@ -168,7 +176,8 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> can be assigned to type <typeparamref name="T"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotAssignableToType<T>(object value, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotAssignableToType<T>([NoEnumeration] object value,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (value is not T)
|
||||
return;
|
||||
@@ -184,7 +193,8 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> can't be assigned to <paramref name="type"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsAssignableToType(object value, Type type, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsAssignableToType([NoEnumeration] object value, Type type,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (type.IsInstanceOfType(value))
|
||||
return;
|
||||
@@ -200,13 +210,48 @@ public static partial class Guard
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> can be assigned to <paramref name="type"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsNotAssignableToType(object value, Type type, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsNotAssignableToType([NoEnumeration] object value, Type type,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (!type.IsInstanceOfType(value))
|
||||
return;
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotAssignableToType(value, type, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input type can be assigned to a specified type.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see cref="Type"/> to test.</param>
|
||||
/// <param name="type">The type to look for.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> can't be assigned to <paramref name="type"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsTypeAssignableToType([NoEnumeration] Type value, Type type,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (type.IsAssignableFrom(value))
|
||||
return;
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsAssignableToType(value, type, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input type can't be assigned to a specified type.
|
||||
/// </summary>
|
||||
/// <param name="value">The input <see cref="Type"/> to test.</param>
|
||||
/// <param name="type">The type to look for.</param>
|
||||
/// <param name="name">The name of the input parameter being tested.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> can be assigned to <paramref name="type"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsTypeNotAssignableToType([NoEnumeration] Type value, Type type,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
{
|
||||
if (!type.IsAssignableFrom(value))
|
||||
return;
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsNotAssignableToType(value, type, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the input value must be the same instance as the target value.
|
||||
@@ -218,7 +263,8 @@ public static partial class Guard
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is not the same instance as <paramref name="target"/>.</exception>
|
||||
/// <remarks>The method is generic to prevent using it with value types.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsReferenceEqualTo<T>(T value, T target, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsReferenceEqualTo<T>([NoEnumeration] T value, T target,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
where T : class
|
||||
{
|
||||
if (ReferenceEquals(value, target))
|
||||
@@ -237,7 +283,8 @@ public static partial class Guard
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is the same instance as <paramref name="target"/>.</exception>
|
||||
/// <remarks>The method is generic to prevent using it with value types.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void IsReferenceNotEqualTo<T>(T value, T target, [CallerArgumentExpression("value")] string name = "")
|
||||
public static void IsReferenceNotEqualTo<T>([NoEnumeration] T value, T target,
|
||||
[CallerArgumentExpression("value")] string name = "")
|
||||
where T : class
|
||||
{
|
||||
if (!ReferenceEquals(value, target))
|
||||
@@ -245,4 +292,4 @@ public static partial class Guard
|
||||
|
||||
ThrowHelper.ThrowArgumentExceptionForIsReferenceNotEqualTo<T>(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,8 @@ public partial class Guard
|
||||
/// <remarks>This method is needed because <see cref="Span{T}"/> can't be used as a generic type parameter.</remarks>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(string name)
|
||||
{
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span<T>).ToTypeString()}) must not be empty.", name);
|
||||
}
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(Span<T>).ToTypeString()}) must not be empty.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotEmpty{T}(ReadOnlySpan{T},string)"/> fails.
|
||||
@@ -30,9 +29,8 @@ public partial class Guard
|
||||
/// <remarks>This method is needed because <see cref="ReadOnlySpan{T}"/> can't be used as a generic type parameter.</remarks>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(string name)
|
||||
{
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must not be empty.", name);
|
||||
}
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must not be empty.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotEmpty{T}(T[],string)"/> (or an overload) fails.
|
||||
@@ -40,8 +38,7 @@ public partial class Guard
|
||||
/// <typeparam name="T">The item of items in the input collection.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotEmpty<T>(string name)
|
||||
{
|
||||
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be empty.", name);
|
||||
}
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be empty.", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,10 @@ public partial class Guard
|
||||
/// <typeparam name="T">The type of <see langword="struct"/> value type being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsDefault<T>(T value, string name)
|
||||
where T : struct => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be the default value {AssertString(default(T))}, was {AssertString(value)}.", name);
|
||||
where T : struct
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be the default value {AssertString(default(T))}, was {AssertString(value)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotDefault{T}"/> fails.
|
||||
@@ -26,21 +29,30 @@ public partial class Guard
|
||||
/// <typeparam name="T">The type of <see langword="struct"/> value type being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotDefault<T>(string name)
|
||||
where T : struct => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be the default value {AssertString(default(T))}.", name);
|
||||
where T : struct
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be the default value {AssertString(default(T))}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsEqualTo{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEqualTo<T>(T value, T target, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be equal to {AssertString(target)}, was {AssertString(value)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsEqualTo<T>(T value, T target, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be equal to {AssertString(target)}, was {AssertString(value)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotEqualTo{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotEqualTo<T>(T value, T target, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be equal to {AssertString(target)}, was {AssertString(value)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotEqualTo<T>(T value, T target, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be equal to {AssertString(target)}, was {AssertString(value)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsBitwiseEqualTo{T}"/> fails.
|
||||
@@ -48,76 +60,103 @@ public partial class Guard
|
||||
/// <typeparam name="T">The type of input values being compared.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForBitwiseEqualTo<T>(T value, T target, string name)
|
||||
where T : unmanaged => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>.", name);
|
||||
where T : unmanaged
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsLessThan{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsLessThan<T>(T value, T maximum, string name) => throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be less than {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsLessThan<T>(T value, T maximum, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, value!,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be less than {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsLessThanOrEqualTo{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo<T>(T value, T maximum, string name) => throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be less than or equal to {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo<T>(T value, T maximum, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, value!,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be less than or equal to {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsGreaterThan{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan<T>(T value, T minimum, string name) => throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be greater than {AssertString(minimum)}, was {AssertString(value)}.");
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan<T>(T value, T minimum, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, value!,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be greater than {AssertString(minimum)}, was {AssertString(value)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsGreaterThanOrEqualTo{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo<T>(T value, T minimum, string name) => throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be greater than or equal to {AssertString(minimum)}, was {AssertString(value)}.");
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo<T>(T value, T minimum, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, value!,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be greater than or equal to {AssertString(minimum)}, was {AssertString(value)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsInRange{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRange<T>(T value, T minimum, T maximum, string name) => throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be in the range given by {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRange<T>(T value, T minimum, T maximum, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, value!,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be in the range given by {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsInRange{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange<T>(T value, T minimum, T maximum, string name) => throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be in the range given by {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
public static void
|
||||
ThrowArgumentOutOfRangeExceptionForIsNotInRange<T>(T value, T minimum, T maximum, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, value!,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be in the range given by {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsBetween{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsBetween<T>(T value, T minimum, T maximum, string name) => throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be between {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsBetween<T>(T value, T minimum, T maximum, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, value!,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be between {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsNotBetween{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween<T>(T value, T minimum, T maximum, string name) => throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be between {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
public static void
|
||||
ThrowArgumentOutOfRangeExceptionForIsNotBetween<T>(T value, T minimum, T maximum, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, value!,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be between {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsBetweenOrEqualTo{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo<T>(T value, T minimum, T maximum, string name) => throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be between or equal to {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
public static void
|
||||
ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo<T>(T value, T minimum, T maximum, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, value!,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be between or equal to {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsNotBetweenOrEqualTo{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values being tested.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo<T>(T value, T minimum, T maximum, string name) => throw new ArgumentOutOfRangeException(name, value!, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be between or equal to {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
public static void
|
||||
ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo<T>(T value, T minimum, T maximum, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, value!,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be between or equal to {AssertString(minimum)} and {AssertString(maximum)}, was {AssertString(value)}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,60 +16,90 @@ public partial class Guard
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsCloseTo(int,int,uint,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}.", name);
|
||||
public static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotCloseTo(int,int,uint,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsCloseTo(long,long,ulong,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}.", name);
|
||||
public static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotCloseTo(long,long,ulong,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsCloseTo(float,float,float,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name);
|
||||
public static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotCloseTo(float,float,float,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsCloseTo(double,double,double,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name);
|
||||
public static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotCloseTo(double,double,double,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsCloseTo(nint,nint,nuint,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsCloseTo(nint value, nint target, nuint delta, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name);
|
||||
public static void ThrowArgumentExceptionForIsCloseTo(nint value, nint target, nuint delta, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotCloseTo(nint,nint,nuint,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotCloseTo(nint value, nint target, nuint delta, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotCloseTo(nint value, nint target, nuint delta, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.",
|
||||
name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,24 +17,33 @@ public partial class Guard
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="CanRead"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForCanRead(Stream stream, string name) => throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support reading.", name);
|
||||
public static void ThrowArgumentExceptionForCanRead(Stream stream, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support reading.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="CanWrite"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) => throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support writing.", name);
|
||||
public static void ThrowArgumentExceptionForCanWrite(Stream stream, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support writing.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="CanSeek"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) => throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support seeking.", name);
|
||||
public static void ThrowArgumentExceptionForCanSeek(Stream stream, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support seeking.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsAtStartPosition"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) => throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) must be at position {AssertString(0)}, was at {AssertString(stream.Position)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) must be at position {AssertString(0)}, was at {AssertString(stream.Position)}.",
|
||||
name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,8 @@ public partial class Guard
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must be null or empty, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must be null or empty, was {AssertString(text)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentNullException"/> or <see cref="ArgumentException"/> when <see cref="IsNotNullOrEmpty"/> fails.
|
||||
@@ -29,8 +30,10 @@ public partial class Guard
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
static Exception GetException(string? text, string name)
|
||||
=> text is null
|
||||
? new ArgumentNullException(name, $"Parameter {AssertString(name)} (string) must not be null or empty, was null.")
|
||||
: new ArgumentException($"Parameter {AssertString(name)} (string) must not be null or empty, was empty.", name);
|
||||
? new ArgumentNullException(name,
|
||||
$"Parameter {AssertString(name)} (string) must not be null or empty, was null.")
|
||||
: new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must not be null or empty, was empty.", name);
|
||||
|
||||
throw GetException(text, name);
|
||||
}
|
||||
@@ -40,7 +43,8 @@ public partial class Guard
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNullOrWhiteSpace(string? text, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must be null or whitespace, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must be null or whitespace, was {AssertString(text)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotNullOrWhiteSpace"/> fails.
|
||||
@@ -51,8 +55,11 @@ public partial class Guard
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
static Exception GetException(string? text, string name)
|
||||
=> text is null
|
||||
? new ArgumentNullException(name, $"Parameter {AssertString(name)} (string) must not be null or whitespace, was null.")
|
||||
: new ArgumentException($"Parameter {AssertString(name)} (string) must not be null or whitespace, was whitespace.", name);
|
||||
? new ArgumentNullException(name,
|
||||
$"Parameter {AssertString(name)} (string) must not be null or whitespace, was null.")
|
||||
: new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must not be null or whitespace, was whitespace.",
|
||||
name);
|
||||
|
||||
throw GetException(text, name);
|
||||
}
|
||||
@@ -62,7 +69,8 @@ public partial class Guard
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty(string text, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must be empty, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must be empty, was {AssertString(text)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotEmpty"/> fails.
|
||||
@@ -76,83 +84,104 @@ public partial class Guard
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsWhiteSpace(string text, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must be whitespace, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must be whitespace, was {AssertString(text)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotWhiteSpace"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotWhiteSpace(string text, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be whitespace, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must not be whitespace, was {AssertString(text)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeEqualTo(string,int,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size equal to {size}, had a size of {text.Length} and was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must have a size equal to {size}, had a size of {text.Length} and was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeNotEqualTo"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must not have a size equal to {size}, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must not have a size equal to {size}, was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeGreaterThan"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size over {size}, had a size of {text.Length} and was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must have a size over {size}, had a size of {text.Length} and was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeGreaterThanOrEqualTo"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size of at least {size}, had a size of {text.Length} and was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must have a size of at least {size}, had a size of {text.Length} and was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeLessThan"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size less than {size}, had a size of {text.Length} and was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must have a size less than {size}, had a size of {text.Length} and was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeLessThanOrEqualTo(string,int,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeEqualTo(string,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name)
|
||||
=> throw new ArgumentException($"The source {AssertString(name)} (string) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"The source {AssertString(name)} (string) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeLessThanOrEqualTo(string,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name)
|
||||
=> throw new ArgumentException($"The source {AssertString(name)} (string) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}.", name);
|
||||
public static void
|
||||
ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"The source {AssertString(name)} (string) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsInRangeFor(int,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(text.Length)} to be a valid index for the target string, was {AssertString(index)}.");
|
||||
=> throw new ArgumentOutOfRangeException(name, index,
|
||||
$"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(text.Length)} to be a valid index for the target string, was {AssertString(index)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsNotInRangeFor(int,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(text.Length)} to be an invalid index for the target string, was {AssertString(index)}.");
|
||||
=> throw new ArgumentOutOfRangeException(name, index,
|
||||
$"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(text.Length)} to be an invalid index for the target string, was {AssertString(index)}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,60 +17,90 @@ public partial class Guard
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsCompleted"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsCompleted(Task task, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be completed, had status {AssertString(task.Status)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsCompleted(Task task, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be completed, had status {AssertString(task.Status)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotCompleted"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be completed, had status {AssertString(task.Status)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be completed, had status {AssertString(task.Status)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsCompletedSuccessfully"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be completed successfully, had status {AssertString(task.Status)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be completed successfully, had status {AssertString(task.Status)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotCompletedSuccessfully"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {AssertString(task.Status)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {AssertString(task.Status)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsFaulted"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsFaulted(Task task, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be faulted, had status {AssertString(task.Status)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsFaulted(Task task, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be faulted, had status {AssertString(task.Status)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotFaulted"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be faulted, had status {AssertString(task.Status)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be faulted, had status {AssertString(task.Status)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsCanceled"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsCanceled(Task task, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be canceled, had status {AssertString(task.Status)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsCanceled(Task task, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must be canceled, had status {AssertString(task.Status)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotCanceled"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be canceled, had status {AssertString(task.Status)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not be canceled, had status {AssertString(task.Status)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasStatusEqualTo"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must have status {status}, had status {AssertString(task.Status)}.", name);
|
||||
public static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must have status {status}, had status {AssertString(task.Status)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasStatusNotEqualTo"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not have status {AssertString(status)}.", name);
|
||||
public static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({task.GetType().ToTypeString()}) must not have status {AssertString(status)}.",
|
||||
name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,10 @@ public partial class Guard
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNull<T>(T value, string name) => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be null, was {AssertString(value)} ({value!.GetType().ToTypeString()}).", name);
|
||||
public static void ThrowArgumentExceptionForIsNull<T>(T value, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be null, was {AssertString(value)} ({value!.GetType().ToTypeString()}).",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNull{T}(T,string)"/> (where <typeparamref name="T"/> is <see langword="struct"/>) fails.
|
||||
@@ -40,66 +43,95 @@ public partial class Guard
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNull<T>(T? value, string name)
|
||||
where T : struct => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T?).ToTypeString()}) must be null, was {AssertString(value)} ({typeof(T).ToTypeString()}).", name);
|
||||
where T : struct
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(T?).ToTypeString()}) must be null, was {AssertString(value)} ({typeof(T).ToTypeString()}).",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentNullException"/> when <see cref="IsNotNull{T}(T,string)"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentNullExceptionForIsNotNull<T>(string name) => throw new ArgumentNullException(name, $"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be not null).");
|
||||
public static void ThrowArgumentNullExceptionForIsNotNull<T>(string name)
|
||||
=> throw new ArgumentNullException(name,
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be not null).");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsOfType{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsOfType<T>(object value, string name) => throw new ArgumentException($"Parameter {AssertString(name)} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}.", name);
|
||||
public static void ThrowArgumentExceptionForIsOfType<T>(object value, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotOfType{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the input value.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotOfType<T>(object value, string name) => throw new ArgumentException($"Parameter {AssertString(name)} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotOfType<T>(object value, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsOfType"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) => throw new ArgumentException($"Parameter {AssertString(name)} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}.", name);
|
||||
public static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotOfType"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) => throw new ArgumentException($"Parameter {AssertString(name)} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsAssignableToType{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being checked against.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsAssignableToType<T>(object value, string name) => throw new ArgumentException($"Parameter {AssertString(name)} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}.", name);
|
||||
public static void ThrowArgumentExceptionForIsAssignableToType<T>(object value, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotAssignableToType{T}"/> fails.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being checked against.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotAssignableToType<T>(object value, string name) => throw new ArgumentException($"Parameter {AssertString(name)} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotAssignableToType<T>(object value, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsAssignableToType"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) => throw new ArgumentException($"Parameter {AssertString(name)} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}.", name);
|
||||
public static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsAssignableToType"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) => throw new ArgumentException($"Parameter {AssertString(name)} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}.", name);
|
||||
public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsReferenceEqualTo{T}"/> fails.
|
||||
@@ -107,7 +139,10 @@ public partial class Guard
|
||||
/// <typeparam name="T">The type of input value being compared.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsReferenceEqualTo<T>(string name)
|
||||
where T : class => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be the same instance as the target object.", name);
|
||||
where T : class
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must be the same instance as the target object.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsReferenceNotEqualTo{T}"/> fails.
|
||||
@@ -115,30 +150,39 @@ public partial class Guard
|
||||
/// <typeparam name="T">The type of input value being compared.</typeparam>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsReferenceNotEqualTo<T>(string name)
|
||||
where T : class => throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be the same instance as the target object.", name);
|
||||
where T : class
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be the same instance as the target object.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsTrue(bool,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsTrue(string name) => throw new ArgumentException($"Parameter {AssertString(name)} must be true, was false.", name);
|
||||
public static void ThrowArgumentExceptionForIsTrue(string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} must be true, was false.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsTrue(bool,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsTrue(string name, string message) => throw new ArgumentException($"Parameter {AssertString(name)} must be true, was false: {AssertString(message)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsTrue(string name, string message)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} must be true, was false: {AssertString(message)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsFalse(bool,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsFalse(string name) => throw new ArgumentException($"Parameter {AssertString(name)} must be false, was true.", name);
|
||||
public static void ThrowArgumentExceptionForIsFalse(string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} must be false, was true.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsFalse(bool,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsFalse(string name, string message) => throw new ArgumentException($"Parameter {AssertString(name)} must be false, was true: {AssertString(message)}.", name);
|
||||
public static void ThrowArgumentExceptionForIsFalse(string name, string message)
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} must be false, was true: {AssertString(message)}.", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ArrayTypeMismatchException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowArrayTypeMismatchException<T>(string? message) => throw new ArrayTypeMismatchException(message);
|
||||
public static T ThrowArrayTypeMismatchException<T>(string? message)
|
||||
=> throw new ArrayTypeMismatchException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArrayTypeMismatchException"/>.
|
||||
@@ -41,7 +42,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ArrayTypeMismatchException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowArrayTypeMismatchException<T>(string? message, Exception? innerException) => throw new ArrayTypeMismatchException(message, innerException);
|
||||
public static T ThrowArrayTypeMismatchException<T>(string? message, Exception? innerException)
|
||||
=> throw new ArrayTypeMismatchException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
@@ -71,7 +73,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowArgumentException<T>(string? message, Exception? innerException) => throw new ArgumentException(message, innerException);
|
||||
public static T ThrowArgumentException<T>(string? message, Exception? innerException)
|
||||
=> throw new ArgumentException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
@@ -82,7 +85,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowArgumentException<T>(string? name, string? message) => throw new ArgumentException(message, name);
|
||||
public static T ThrowArgumentException<T>(string? name, string? message)
|
||||
=> throw new ArgumentException(message, name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
@@ -94,7 +98,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowArgumentException<T>(string? name, string? message, Exception? innerException) => throw new ArgumentException(message, name, innerException);
|
||||
public static T ThrowArgumentException<T>(string? name, string? message, Exception? innerException)
|
||||
=> throw new ArgumentException(message, name, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentNullException"/>.
|
||||
@@ -124,7 +129,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ArgumentNullException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowArgumentNullException<T>(string? name, Exception? innerException) => throw new ArgumentNullException(name, innerException);
|
||||
public static T ThrowArgumentNullException<T>(string? name, Exception? innerException)
|
||||
=> throw new ArgumentNullException(name, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentNullException"/>.
|
||||
@@ -135,7 +141,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ArgumentNullException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowArgumentNullException<T>(string? name, string? message) => throw new ArgumentNullException(name, message);
|
||||
public static T ThrowArgumentNullException<T>(string? name, string? message)
|
||||
=> throw new ArgumentNullException(name, message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
@@ -165,7 +172,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowArgumentOutOfRangeException<T>(string? name, Exception? innerException) => throw new ArgumentOutOfRangeException(name, innerException);
|
||||
public static T ThrowArgumentOutOfRangeException<T>(string? name, Exception? innerException)
|
||||
=> throw new ArgumentOutOfRangeException(name, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
@@ -176,7 +184,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowArgumentOutOfRangeException<T>(string? name, string? message) => throw new ArgumentOutOfRangeException(name, message);
|
||||
public static T ThrowArgumentOutOfRangeException<T>(string? name, string? message)
|
||||
=> throw new ArgumentOutOfRangeException(name, message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
@@ -188,7 +197,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowArgumentOutOfRangeException<T>(string? name, object? value, string? message) => throw new ArgumentOutOfRangeException(name, value, message);
|
||||
public static T ThrowArgumentOutOfRangeException<T>(string? name, object? value, string? message)
|
||||
=> throw new ArgumentOutOfRangeException(name, value, message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="COMException"/>.
|
||||
@@ -218,7 +228,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="COMException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowCOMException<T>(string? message, Exception? innerException) => throw new COMException(message, innerException);
|
||||
public static T ThrowCOMException<T>(string? message, Exception? innerException)
|
||||
=> throw new COMException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="COMException"/>.
|
||||
@@ -259,7 +270,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ExternalException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowExternalException<T>(string? message, Exception? innerException) => throw new ExternalException(message, innerException);
|
||||
public static T ThrowExternalException<T>(string? message, Exception? innerException)
|
||||
=> throw new ExternalException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ExternalException"/>.
|
||||
@@ -270,7 +282,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ExternalException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowExternalException<T>(string? message, int error) => throw new ExternalException(message, error);
|
||||
public static T ThrowExternalException<T>(string? message, int error)
|
||||
=> throw new ExternalException(message, error);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="FormatException"/>.
|
||||
@@ -300,7 +313,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="FormatException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowFormatException<T>(string? message, Exception? innerException) => throw new FormatException(message, innerException);
|
||||
public static T ThrowFormatException<T>(string? message, Exception? innerException)
|
||||
=> throw new FormatException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InsufficientMemoryException"/>.
|
||||
@@ -319,7 +333,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="InsufficientMemoryException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowInsufficientMemoryException<T>(string? message) => throw new InsufficientMemoryException(message);
|
||||
public static T ThrowInsufficientMemoryException<T>(string? message)
|
||||
=> throw new InsufficientMemoryException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InsufficientMemoryException"/>.
|
||||
@@ -330,7 +345,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="InsufficientMemoryException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowInsufficientMemoryException<T>(string? message, Exception? innerException) => throw new InsufficientMemoryException(message, innerException);
|
||||
public static T ThrowInsufficientMemoryException<T>(string? message, Exception? innerException)
|
||||
=> throw new InsufficientMemoryException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InvalidDataException"/>.
|
||||
@@ -360,7 +376,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="InvalidDataException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowInvalidDataException<T>(string? message, Exception? innerException) => throw new InvalidDataException(message, innerException);
|
||||
public static T ThrowInvalidDataException<T>(string? message, Exception? innerException)
|
||||
=> throw new InvalidDataException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InvalidOperationException"/>.
|
||||
@@ -390,7 +407,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="InvalidOperationException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowInvalidOperationException<T>(string? message, Exception? innerException) => throw new InvalidOperationException(message, innerException);
|
||||
public static T ThrowInvalidOperationException<T>(string? message, Exception? innerException)
|
||||
=> throw new InvalidOperationException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="LockRecursionException"/>.
|
||||
@@ -420,7 +438,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="LockRecursionException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowLockRecursionException<T>(string? message, Exception? innerException) => throw new LockRecursionException(message, innerException);
|
||||
public static T ThrowLockRecursionException<T>(string? message, Exception? innerException)
|
||||
=> throw new LockRecursionException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingFieldException"/>.
|
||||
@@ -450,7 +469,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="MissingFieldException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowMissingFieldException<T>(string? message, Exception? innerException) => throw new MissingFieldException(message, innerException);
|
||||
public static T ThrowMissingFieldException<T>(string? message, Exception? innerException)
|
||||
=> throw new MissingFieldException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingFieldException"/>.
|
||||
@@ -461,7 +481,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="MissingFieldException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowMissingFieldException<T>(string? className, string? fieldName) => throw new MissingFieldException(className, fieldName);
|
||||
public static T ThrowMissingFieldException<T>(string? className, string? fieldName)
|
||||
=> throw new MissingFieldException(className, fieldName);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMemberException"/>.
|
||||
@@ -491,7 +512,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="MissingMemberException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowMissingMemberException<T>(string? message, Exception? innerException) => throw new MissingMemberException(message, innerException);
|
||||
public static T ThrowMissingMemberException<T>(string? message, Exception? innerException)
|
||||
=> throw new MissingMemberException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMemberException"/>.
|
||||
@@ -502,7 +524,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="MissingMemberException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowMissingMemberException<T>(string? className, string? memberName) => throw new MissingMemberException(className, memberName);
|
||||
public static T ThrowMissingMemberException<T>(string? className, string? memberName)
|
||||
=> throw new MissingMemberException(className, memberName);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMethodException"/>.
|
||||
@@ -532,7 +555,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="MissingMethodException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowMissingMethodException<T>(string? message, Exception? innerException) => throw new MissingMethodException(message, innerException);
|
||||
public static T ThrowMissingMethodException<T>(string? message, Exception? innerException)
|
||||
=> throw new MissingMethodException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMethodException"/>.
|
||||
@@ -543,7 +567,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="MissingMethodException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowMissingMethodException<T>(string? className, string? methodName) => throw new MissingMethodException(className, methodName);
|
||||
public static T ThrowMissingMethodException<T>(string? className, string? methodName)
|
||||
=> throw new MissingMethodException(className, methodName);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="NotSupportedException"/>.
|
||||
@@ -573,7 +598,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="NotSupportedException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowNotSupportedException<T>(string? message, Exception? innerException) => throw new NotSupportedException(message, innerException);
|
||||
public static T ThrowNotSupportedException<T>(string? message, Exception? innerException)
|
||||
=> throw new NotSupportedException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ObjectDisposedException"/>.
|
||||
@@ -583,7 +609,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ObjectDisposedException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowObjectDisposedException<T>(string? objectName) => throw new ObjectDisposedException(objectName);
|
||||
public static T ThrowObjectDisposedException<T>(string? objectName)
|
||||
=> throw new ObjectDisposedException(objectName);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ObjectDisposedException"/>.
|
||||
@@ -594,7 +621,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ObjectDisposedException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowObjectDisposedException<T>(string? objectName, Exception? innerException) => throw new ObjectDisposedException(objectName, innerException);
|
||||
public static T ThrowObjectDisposedException<T>(string? objectName, Exception? innerException)
|
||||
=> throw new ObjectDisposedException(objectName, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ObjectDisposedException"/>.
|
||||
@@ -605,7 +633,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="ObjectDisposedException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowObjectDisposedException<T>(string? objectName, string? message) => throw new ObjectDisposedException(objectName, message);
|
||||
public static T ThrowObjectDisposedException<T>(string? objectName, string? message)
|
||||
=> throw new ObjectDisposedException(objectName, message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
@@ -624,7 +653,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowOperationCanceledException<T>(string? message) => throw new OperationCanceledException(message);
|
||||
public static T ThrowOperationCanceledException<T>(string? message)
|
||||
=> throw new OperationCanceledException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
@@ -635,7 +665,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowOperationCanceledException<T>(string? message, Exception? innerException) => throw new OperationCanceledException(message, innerException);
|
||||
public static T ThrowOperationCanceledException<T>(string? message, Exception? innerException)
|
||||
=> throw new OperationCanceledException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
@@ -645,7 +676,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowOperationCanceledException<T>(CancellationToken token) => throw new OperationCanceledException(token);
|
||||
public static T ThrowOperationCanceledException<T>(CancellationToken token)
|
||||
=> throw new OperationCanceledException(token);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
@@ -656,7 +688,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowOperationCanceledException<T>(string? message, CancellationToken token) => throw new OperationCanceledException(message, token);
|
||||
public static T ThrowOperationCanceledException<T>(string? message, CancellationToken token)
|
||||
=> throw new OperationCanceledException(message, token);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
@@ -668,7 +701,9 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowOperationCanceledException<T>(string? message, Exception? innerException, CancellationToken token) => throw new OperationCanceledException(message, innerException, token);
|
||||
public static T ThrowOperationCanceledException<T>(string? message, Exception? innerException,
|
||||
CancellationToken token)
|
||||
=> throw new OperationCanceledException(message, innerException, token);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="PlatformNotSupportedException"/>.
|
||||
@@ -687,7 +722,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="PlatformNotSupportedException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowPlatformNotSupportedException<T>(string? message) => throw new PlatformNotSupportedException(message);
|
||||
public static T ThrowPlatformNotSupportedException<T>(string? message)
|
||||
=> throw new PlatformNotSupportedException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="PlatformNotSupportedException"/>.
|
||||
@@ -698,7 +734,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="PlatformNotSupportedException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowPlatformNotSupportedException<T>(string? message, Exception? innerException) => throw new PlatformNotSupportedException(message, innerException);
|
||||
public static T ThrowPlatformNotSupportedException<T>(string? message, Exception? innerException)
|
||||
=> throw new PlatformNotSupportedException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="SynchronizationLockException"/>.
|
||||
@@ -717,7 +754,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="SynchronizationLockException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowSynchronizationLockException<T>(string? message) => throw new SynchronizationLockException(message);
|
||||
public static T ThrowSynchronizationLockException<T>(string? message)
|
||||
=> throw new SynchronizationLockException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="SynchronizationLockException"/>.
|
||||
@@ -728,7 +766,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="SynchronizationLockException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowSynchronizationLockException<T>(string? message, Exception? innerException) => throw new SynchronizationLockException(message, innerException);
|
||||
public static T ThrowSynchronizationLockException<T>(string? message, Exception? innerException)
|
||||
=> throw new SynchronizationLockException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="TimeoutException"/>.
|
||||
@@ -758,7 +797,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="TimeoutException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowTimeoutException<T>(string? message, Exception? innerException) => throw new TimeoutException(message, innerException);
|
||||
public static T ThrowTimeoutException<T>(string? message, Exception? innerException)
|
||||
=> throw new TimeoutException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="UnauthorizedAccessException"/>.
|
||||
@@ -777,7 +817,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="UnauthorizedAccessException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowUnauthorizedAccessException<T>(string? message) => throw new UnauthorizedAccessException(message);
|
||||
public static T ThrowUnauthorizedAccessException<T>(string? message)
|
||||
=> throw new UnauthorizedAccessException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="UnauthorizedAccessException"/>.
|
||||
@@ -788,7 +829,8 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="UnauthorizedAccessException">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowUnauthorizedAccessException<T>(string? message, Exception? innerException) => throw new UnauthorizedAccessException(message, innerException);
|
||||
public static T ThrowUnauthorizedAccessException<T>(string? message, Exception? innerException)
|
||||
=> throw new UnauthorizedAccessException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="Win32Exception"/>.
|
||||
@@ -839,5 +881,6 @@ public static partial class ThrowHelper
|
||||
/// <exception cref="Win32Exception">Thrown with the specified parameter.</exception>
|
||||
/// <returns>This method always throws, so it actually never returns a value.</returns>
|
||||
[DoesNotReturn]
|
||||
public static T ThrowWin32Exception<T>(string? message, Exception? innerException) => throw new Win32Exception(message, innerException);
|
||||
}
|
||||
public static T ThrowWin32Exception<T>(string? message, Exception? innerException)
|
||||
=> throw new Win32Exception(message, innerException);
|
||||
}
|
||||
@@ -28,7 +28,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArrayTypeMismatchException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArrayTypeMismatchException(string? message) => throw new ArrayTypeMismatchException(message);
|
||||
public static void ThrowArrayTypeMismatchException(string? message)
|
||||
=> throw new ArrayTypeMismatchException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArrayTypeMismatchException"/>.
|
||||
@@ -37,7 +38,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ArrayTypeMismatchException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArrayTypeMismatchException(string? message, Exception? innerException) => throw new ArrayTypeMismatchException(message, innerException);
|
||||
public static void ThrowArrayTypeMismatchException(string? message, Exception? innerException)
|
||||
=> throw new ArrayTypeMismatchException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
@@ -61,7 +63,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentException(string? message, Exception? innerException) => throw new ArgumentException(message, innerException);
|
||||
public static void ThrowArgumentException(string? message, Exception? innerException)
|
||||
=> throw new ArgumentException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
@@ -70,7 +73,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentException(string? name, string? message) => throw new ArgumentException(message, name);
|
||||
public static void ThrowArgumentException(string? name, string? message)
|
||||
=> throw new ArgumentException(message, name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
@@ -80,7 +84,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentException(string? name, string? message, Exception? innerException) => throw new ArgumentException(message, name, innerException);
|
||||
public static void ThrowArgumentException(string? name, string? message, Exception? innerException)
|
||||
=> throw new ArgumentException(message, name, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentNullException"/>.
|
||||
@@ -104,7 +109,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentNullException(string? name, Exception? innerException) => throw new ArgumentNullException(name, innerException);
|
||||
public static void ThrowArgumentNullException(string? name, Exception? innerException)
|
||||
=> throw new ArgumentNullException(name, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentNullException"/>.
|
||||
@@ -113,7 +119,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentNullException(string? name, string? message) => throw new ArgumentNullException(name, message);
|
||||
public static void ThrowArgumentNullException(string? name, string? message)
|
||||
=> throw new ArgumentNullException(name, message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
@@ -137,7 +144,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeException(string? name, Exception? innerException) => throw new ArgumentOutOfRangeException(name, innerException);
|
||||
public static void ThrowArgumentOutOfRangeException(string? name, Exception? innerException)
|
||||
=> throw new ArgumentOutOfRangeException(name, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
@@ -146,7 +154,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeException(string? name, string? message) => throw new ArgumentOutOfRangeException(name, message);
|
||||
public static void ThrowArgumentOutOfRangeException(string? name, string? message)
|
||||
=> throw new ArgumentOutOfRangeException(name, message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
@@ -156,7 +165,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeException(string? name, object? value, string? message) => throw new ArgumentOutOfRangeException(name, value, message);
|
||||
public static void ThrowArgumentOutOfRangeException(string? name, object? value, string? message)
|
||||
=> throw new ArgumentOutOfRangeException(name, value, message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="COMException"/>.
|
||||
@@ -180,7 +190,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="COMException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowCOMException(string? message, Exception? innerException) => throw new COMException(message, innerException);
|
||||
public static void ThrowCOMException(string? message, Exception? innerException)
|
||||
=> throw new COMException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="COMException"/>.
|
||||
@@ -213,7 +224,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ExternalException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowExternalException(string? message, Exception? innerException) => throw new ExternalException(message, innerException);
|
||||
public static void ThrowExternalException(string? message, Exception? innerException)
|
||||
=> throw new ExternalException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ExternalException"/>.
|
||||
@@ -222,7 +234,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="error">The HRESULT of the error to include.</param>
|
||||
/// <exception cref="ExternalException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowExternalException(string? message, int error) => throw new ExternalException(message, error);
|
||||
public static void ThrowExternalException(string? message, int error)
|
||||
=> throw new ExternalException(message, error);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="FormatException"/>.
|
||||
@@ -246,7 +259,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="FormatException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowFormatException(string? message, Exception? innerException) => throw new FormatException(message, innerException);
|
||||
public static void ThrowFormatException(string? message, Exception? innerException)
|
||||
=> throw new FormatException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InsufficientMemoryException"/>.
|
||||
@@ -261,7 +275,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="InsufficientMemoryException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowInsufficientMemoryException(string? message) => throw new InsufficientMemoryException(message);
|
||||
public static void ThrowInsufficientMemoryException(string? message)
|
||||
=> throw new InsufficientMemoryException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InsufficientMemoryException"/>.
|
||||
@@ -270,7 +285,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="InsufficientMemoryException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowInsufficientMemoryException(string? message, Exception? innerException) => throw new InsufficientMemoryException(message, innerException);
|
||||
public static void ThrowInsufficientMemoryException(string? message, Exception? innerException)
|
||||
=> throw new InsufficientMemoryException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InvalidDataException"/>.
|
||||
@@ -294,7 +310,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="InvalidDataException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowInvalidDataException(string? message, Exception? innerException) => throw new InvalidDataException(message, innerException);
|
||||
public static void ThrowInvalidDataException(string? message, Exception? innerException)
|
||||
=> throw new InvalidDataException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InvalidOperationException"/>.
|
||||
@@ -318,7 +335,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowInvalidOperationException(string? message, Exception? innerException) => throw new InvalidOperationException(message, innerException);
|
||||
public static void ThrowInvalidOperationException(string? message, Exception? innerException)
|
||||
=> throw new InvalidOperationException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="LockRecursionException"/>.
|
||||
@@ -342,7 +360,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="LockRecursionException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowLockRecursionException(string? message, Exception? innerException) => throw new LockRecursionException(message, innerException);
|
||||
public static void ThrowLockRecursionException(string? message, Exception? innerException)
|
||||
=> throw new LockRecursionException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingFieldException"/>.
|
||||
@@ -366,7 +385,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="MissingFieldException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingFieldException(string? message, Exception? innerException) => throw new MissingFieldException(message, innerException);
|
||||
public static void ThrowMissingFieldException(string? message, Exception? innerException)
|
||||
=> throw new MissingFieldException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingFieldException"/>.
|
||||
@@ -375,7 +395,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="fieldName">The target field being retrieved.</param>
|
||||
/// <exception cref="MissingFieldException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingFieldException(string? className, string? fieldName) => throw new MissingFieldException(className, fieldName);
|
||||
public static void ThrowMissingFieldException(string? className, string? fieldName)
|
||||
=> throw new MissingFieldException(className, fieldName);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMemberException"/>.
|
||||
@@ -399,7 +420,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="MissingMemberException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingMemberException(string? message, Exception? innerException) => throw new MissingMemberException(message, innerException);
|
||||
public static void ThrowMissingMemberException(string? message, Exception? innerException)
|
||||
=> throw new MissingMemberException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMemberException"/>.
|
||||
@@ -408,7 +430,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="memberName">The target member being retrieved.</param>
|
||||
/// <exception cref="MissingMemberException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingMemberException(string? className, string? memberName) => throw new MissingMemberException(className, memberName);
|
||||
public static void ThrowMissingMemberException(string? className, string? memberName)
|
||||
=> throw new MissingMemberException(className, memberName);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMethodException"/>.
|
||||
@@ -432,7 +455,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="MissingMethodException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingMethodException(string? message, Exception? innerException) => throw new MissingMethodException(message, innerException);
|
||||
public static void ThrowMissingMethodException(string? message, Exception? innerException)
|
||||
=> throw new MissingMethodException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMethodException"/>.
|
||||
@@ -441,7 +465,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="methodName">The target method being retrieved.</param>
|
||||
/// <exception cref="MissingMethodException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowMissingMethodException(string? className, string? methodName) => throw new MissingMethodException(className, methodName);
|
||||
public static void ThrowMissingMethodException(string? className, string? methodName)
|
||||
=> throw new MissingMethodException(className, methodName);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="NotSupportedException"/>.
|
||||
@@ -465,7 +490,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="NotSupportedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowNotSupportedException(string? message, Exception? innerException) => throw new NotSupportedException(message, innerException);
|
||||
public static void ThrowNotSupportedException(string? message, Exception? innerException)
|
||||
=> throw new NotSupportedException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ObjectDisposedException"/>.
|
||||
@@ -473,7 +499,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="objectName">The name of the disposed object.</param>
|
||||
/// <exception cref="ObjectDisposedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowObjectDisposedException(string? objectName) => throw new ObjectDisposedException(objectName);
|
||||
public static void ThrowObjectDisposedException(string? objectName)
|
||||
=> throw new ObjectDisposedException(objectName);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ObjectDisposedException"/>.
|
||||
@@ -482,7 +509,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="ObjectDisposedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowObjectDisposedException(string? objectName, Exception? innerException) => throw new ObjectDisposedException(objectName, innerException);
|
||||
public static void ThrowObjectDisposedException(string? objectName, Exception? innerException)
|
||||
=> throw new ObjectDisposedException(objectName, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ObjectDisposedException"/>.
|
||||
@@ -491,7 +519,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ObjectDisposedException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowObjectDisposedException(string? objectName, string? message) => throw new ObjectDisposedException(objectName, message);
|
||||
public static void ThrowObjectDisposedException(string? objectName, string? message)
|
||||
=> throw new ObjectDisposedException(objectName, message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
@@ -506,7 +535,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowOperationCanceledException(string? message) => throw new OperationCanceledException(message);
|
||||
public static void ThrowOperationCanceledException(string? message)
|
||||
=> throw new OperationCanceledException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
@@ -515,7 +545,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowOperationCanceledException(string? message, Exception? innerException) => throw new OperationCanceledException(message, innerException);
|
||||
public static void ThrowOperationCanceledException(string? message, Exception? innerException)
|
||||
=> throw new OperationCanceledException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
@@ -523,7 +554,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="token">The <see cref="CancellationToken"/> in use.</param>
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowOperationCanceledException(CancellationToken token) => throw new OperationCanceledException(token);
|
||||
public static void ThrowOperationCanceledException(CancellationToken token)
|
||||
=> throw new OperationCanceledException(token);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
@@ -532,7 +564,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="token">The <see cref="CancellationToken"/> in use.</param>
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowOperationCanceledException(string? message, CancellationToken token) => throw new OperationCanceledException(message, token);
|
||||
public static void ThrowOperationCanceledException(string? message, CancellationToken token)
|
||||
=> throw new OperationCanceledException(message, token);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="OperationCanceledException"/>.
|
||||
@@ -542,7 +575,9 @@ public static partial class ThrowHelper
|
||||
/// <param name="token">The <see cref="CancellationToken"/> in use.</param>
|
||||
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowOperationCanceledException(string? message, Exception? innerException, CancellationToken token) => throw new OperationCanceledException(message, innerException, token);
|
||||
public static void ThrowOperationCanceledException(string? message, Exception? innerException,
|
||||
CancellationToken token)
|
||||
=> throw new OperationCanceledException(message, innerException, token);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="PlatformNotSupportedException"/>.
|
||||
@@ -557,7 +592,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="PlatformNotSupportedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowPlatformNotSupportedException(string? message) => throw new PlatformNotSupportedException(message);
|
||||
public static void ThrowPlatformNotSupportedException(string? message)
|
||||
=> throw new PlatformNotSupportedException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="PlatformNotSupportedException"/>.
|
||||
@@ -566,7 +602,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="PlatformNotSupportedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowPlatformNotSupportedException(string? message, Exception? innerException) => throw new PlatformNotSupportedException(message, innerException);
|
||||
public static void ThrowPlatformNotSupportedException(string? message, Exception? innerException)
|
||||
=> throw new PlatformNotSupportedException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="SynchronizationLockException"/>.
|
||||
@@ -581,7 +618,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="SynchronizationLockException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowSynchronizationLockException(string? message) => throw new SynchronizationLockException(message);
|
||||
public static void ThrowSynchronizationLockException(string? message)
|
||||
=> throw new SynchronizationLockException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="SynchronizationLockException"/>.
|
||||
@@ -590,7 +628,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="SynchronizationLockException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowSynchronizationLockException(string? message, Exception? innerException) => throw new SynchronizationLockException(message, innerException);
|
||||
public static void ThrowSynchronizationLockException(string? message, Exception? innerException)
|
||||
=> throw new SynchronizationLockException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="TimeoutException"/>.
|
||||
@@ -614,7 +653,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="TimeoutException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowTimeoutException(string? message, Exception? innerException) => throw new TimeoutException(message, innerException);
|
||||
public static void ThrowTimeoutException(string? message, Exception? innerException)
|
||||
=> throw new TimeoutException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="UnauthorizedAccessException"/>.
|
||||
@@ -629,7 +669,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="UnauthorizedAccessException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowUnauthorizedAccessException(string? message) => throw new UnauthorizedAccessException(message);
|
||||
public static void ThrowUnauthorizedAccessException(string? message)
|
||||
=> throw new UnauthorizedAccessException(message);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="UnauthorizedAccessException"/>.
|
||||
@@ -638,7 +679,8 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="UnauthorizedAccessException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowUnauthorizedAccessException(string? message, Exception? innerException) => throw new UnauthorizedAccessException(message, innerException);
|
||||
public static void ThrowUnauthorizedAccessException(string? message, Exception? innerException)
|
||||
=> throw new UnauthorizedAccessException(message, innerException);
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="Win32Exception"/>.
|
||||
@@ -679,5 +721,6 @@ public static partial class ThrowHelper
|
||||
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
|
||||
/// <exception cref="Win32Exception">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowWin32Exception(string? message, Exception? innerException) => throw new Win32Exception(message, innerException);
|
||||
}
|
||||
public static void ThrowWin32Exception(string? message, Exception? innerException)
|
||||
=> throw new Win32Exception(message, innerException);
|
||||
}
|
||||
Reference in New Issue
Block a user