Files
sharpcompress/src/SharpCompress/ThrowHelper.cs
2026-04-04 10:44:23 +01:00

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);
}
}
}