mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-07-09 02:26:47 +00:00
81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace SharpCompress;
|
|
|
|
internal static class ThrowHelper
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void ThrowIfNull([NotNull] object? argument, string? paramName = null)
|
|
{
|
|
if (argument is null)
|
|
{
|
|
throw new ArgumentNullException(paramName);
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void ThrowIfNegative(int value, string? paramName = null)
|
|
{
|
|
if (value < 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(paramName);
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void ThrowIfNegative(long value, string? paramName = null)
|
|
{
|
|
if (value < 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(paramName);
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void ThrowIfNegativeOrZero(int value, string? paramName = null)
|
|
{
|
|
if (value <= 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(paramName);
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void ThrowIfLessThan(int value, int other, string? paramName = null)
|
|
{
|
|
if (value < other)
|
|
{
|
|
throw new ArgumentOutOfRangeException(paramName);
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void ThrowIfGreaterThan(int value, int other, string? paramName = null)
|
|
{
|
|
if (value > other)
|
|
{
|
|
throw new ArgumentOutOfRangeException(paramName);
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void ThrowIfGreaterThan(long value, long other, string? paramName = null)
|
|
{
|
|
if (value > other)
|
|
{
|
|
throw new ArgumentOutOfRangeException(paramName);
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void ThrowIfGreaterThan(uint value, uint other, string? paramName = null)
|
|
{
|
|
if (value > other)
|
|
{
|
|
throw new ArgumentOutOfRangeException(paramName);
|
|
}
|
|
}
|
|
}
|