diff --git a/src/ComputeSharp.Core/Polyfills/ArgumentNullExceptionExtensions.cs b/src/ComputeSharp.Core/Polyfills/ArgumentNullExceptionExtensions.cs
index 7f6e276d..ab256f00 100644
--- a/src/ComputeSharp.Core/Polyfills/ArgumentNullExceptionExtensions.cs
+++ b/src/ComputeSharp.Core/Polyfills/ArgumentNullExceptionExtensions.cs
@@ -55,7 +55,7 @@ internal static class ArgumentNullExceptionExtensions
///
[DoesNotReturn]
- public static void Throw(string? parameterName)
+ private static void Throw(string? parameterName)
{
throw new ArgumentNullException(parameterName);
}
diff --git a/src/ComputeSharp.Core/Polyfills/ArgumentOutOfRangeExceptionExtensions.cs b/src/ComputeSharp.Core/Polyfills/ArgumentOutOfRangeExceptionExtensions.cs
new file mode 100644
index 00000000..8a6e2986
--- /dev/null
+++ b/src/ComputeSharp.Core/Polyfills/ArgumentOutOfRangeExceptionExtensions.cs
@@ -0,0 +1,36 @@
+using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
+
+namespace System;
+
+///
+/// Throw helper extensions for .
+///
+internal static class ArgumentOutOfRangeExceptionExtensions
+{
+ ///
+ /// Throws an if is negative.
+ ///
+ /// Dummy value to invoke the extension upon (always pass .
+ /// The argument to validate as non-negative.
+ /// The name of the parameter with which corresponds.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void ThrowIfNegative(this ArgumentOutOfRangeException? _, int value, [CallerArgumentExpression(nameof(value))] string? parameterName = null)
+ {
+ if (value < 0)
+ {
+ Throw(parameterName);
+ }
+ }
+
+ ///
+ /// Throws an for a given parameter name.
+ ///
+ /// The name of the parameter to report in the exception.
+ /// Thrown with .
+ [DoesNotReturn]
+ private static void Throw(string? parameterName)
+ {
+ throw new ArgumentOutOfRangeException(parameterName);
+ }
+}
diff --git a/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs b/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs
index 1534cc01..4f40f97f 100644
--- a/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs
@@ -1,6 +1,5 @@
using System;
using System.Runtime.InteropServices;
-using CommunityToolkit.Diagnostics;
using ComputeSharp.Resources;
#if !NET6_0_OR_GREATER
using GC = ComputeSharp.NetStandard.GC;
@@ -39,7 +38,7 @@ public static class BufferExtensions
where T : unmanaged
{
default(ArgumentNullException).ThrowIfNull(source);
- Guard.IsGreaterThanOrEqualTo(count, 0);
+ default(ArgumentOutOfRangeException).ThrowIfNegative(count);
T[] data = GC.AllocateUninitializedArray(count);
diff --git a/src/ComputeSharp/Graphics/Extensions/Texture1DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Texture1DExtensions.cs
index c91bd4f5..5b054655 100644
--- a/src/ComputeSharp/Graphics/Extensions/Texture1DExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/Texture1DExtensions.cs
@@ -1,6 +1,5 @@
using System;
using System.Runtime.InteropServices;
-using CommunityToolkit.Diagnostics;
using ComputeSharp.Resources;
namespace ComputeSharp;
@@ -40,7 +39,7 @@ public static class Texture1DExtensions
where T : unmanaged
{
default(ArgumentNullException).ThrowIfNull(source);
- Guard.IsGreaterThanOrEqualTo(width, 0);
+ default(ArgumentOutOfRangeException).ThrowIfNegative(width);
T[] data = new T[width];
diff --git a/src/ComputeSharp/Graphics/Extensions/Texture2DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Texture2DExtensions.cs
index 56accba3..c6b57168 100644
--- a/src/ComputeSharp/Graphics/Extensions/Texture2DExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/Texture2DExtensions.cs
@@ -45,8 +45,8 @@ public static class Texture2DExtensions
where T : unmanaged
{
default(ArgumentNullException).ThrowIfNull(source);
- Guard.IsGreaterThanOrEqualTo(width, 0);
- Guard.IsGreaterThanOrEqualTo(height, 0);
+ default(ArgumentOutOfRangeException).ThrowIfNegative(width);
+ default(ArgumentOutOfRangeException).ThrowIfNegative(height);
T[,] data = new T[height, width];
diff --git a/src/ComputeSharp/Graphics/Extensions/Texture3DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Texture3DExtensions.cs
index db76bfee..6dcfbedf 100644
--- a/src/ComputeSharp/Graphics/Extensions/Texture3DExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/Texture3DExtensions.cs
@@ -49,9 +49,9 @@ public static class Texture3DExtensions
where T : unmanaged
{
default(ArgumentNullException).ThrowIfNull(source);
- Guard.IsGreaterThanOrEqualTo(width, 0);
- Guard.IsGreaterThanOrEqualTo(height, 0);
- Guard.IsGreaterThanOrEqualTo(depth, 0);
+ default(ArgumentOutOfRangeException).ThrowIfNegative(width);
+ default(ArgumentOutOfRangeException).ThrowIfNegative(height);
+ default(ArgumentOutOfRangeException).ThrowIfNegative(depth);
T[,,] data = new T[depth, height, width];