#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ output extension=".cs" #>
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
namespace SixLabors
///
/// Provides methods to protect against invalid parameters.
///
internal static partial class Guard
{
<#
var types = new[] { "byte", "sbyte", "short", "ushort", "char", "int", "uint", "float", "long", "ulong", "double", "decimal" };
for (var i = 0; i < types.Length; i++)
{
if (i > 0) WriteLine("");
var T = types[i];
#>
///
/// Ensures that the specified value is less than a maximum value.
///
/// The target value, which should be validated.
/// The maximum value.
/// The name of the parameter that is to be checked.
///
/// is greater than the maximum value.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MustBeLessThan(<#=T#> value, <#=T#> max, string parameterName)
{
if (value < max)
{
return;
}
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
}
///
/// Verifies that the specified value is less than or equal to a maximum value
/// and throws an exception if it is not.
///
/// The target value, which should be validated.
/// The maximum value.
/// The name of the parameter that is to be checked.
///
/// is greater than the maximum value.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MustBeLessThanOrEqualTo(<#=T#> value, <#=T#> max, string parameterName)
{
if (value <= max)
{
return;
}
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
}
///
/// Verifies that the specified value is greater than a minimum value
/// and throws an exception if it is not.
///
/// The target value, which should be validated.
/// The minimum value.
/// The name of the parameter that is to be checked.
///
/// is less than the minimum value.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MustBeGreaterThan(<#=T#> value, <#=T#> min, string parameterName)
{
if (value > min)
{
return;
}
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
}
///
/// Verifies that the specified value is greater than or equal to a minimum value
/// and throws an exception if it is not.
///
/// The target value, which should be validated.
/// The minimum value.
/// The name of the parameter that is to be checked.
///
/// is less than the minimum value.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MustBeGreaterThanOrEqualTo(<#=T#> value, <#=T#> min, string parameterName)
{
if (value >= min)
{
return;
}
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
}
///
/// Verifies that the specified value is greater than or equal to a minimum value and less than
/// or equal to a maximum value and throws an exception if it is not.
///
/// The target value, which should be validated.
/// The minimum value.
/// The maximum value.
/// The name of the parameter that is to be checked.
///
/// is less than the minimum value of greater than the maximum value.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MustBeBetweenOrEqualTo(<#=T#> value, <#=T#> min, <#=T#> max, string parameterName)
{
if (value >= min && value <= max)
{
return;
}
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
}
<#
}
#>
}