diff --git a/src/ComputeSharp.Core/Polyfills/ObjectDisposedExceptionExtensions.cs b/src/ComputeSharp.Core/Polyfills/ObjectDisposedExceptionExtensions.cs
new file mode 100644
index 00000000..21335f80
--- /dev/null
+++ b/src/ComputeSharp.Core/Polyfills/ObjectDisposedExceptionExtensions.cs
@@ -0,0 +1,60 @@
+using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
+
+namespace System;
+
+///
+/// Throw helper extensions for .
+///
+internal static class ObjectDisposedExceptionExtensions
+{
+ ///
+ /// Throws an if is .
+ ///
+ /// Dummy value to invoke the extension upon (always pass .
+ /// The condition indicating whether has been disposed.
+ /// The instance that can be signaled as being disposed.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void ThrowIf(this ObjectDisposedException? _, [DoesNotReturnIf(true)] bool condition, object disposableInstance)
+ {
+ if (condition)
+ {
+ Throw(disposableInstance);
+ }
+ }
+
+ ///
+ /// Throws an if is .
+ ///
+ /// Dummy value to invoke the extension upon (always pass .
+ /// The instance to check to determine whether the target instance has been disposed.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void ThrowIfNull(this ObjectDisposedException? _, [NotNull] object? validationObject)
+ {
+ if (validationObject is null)
+ {
+ Throw();
+ }
+ }
+
+ ///
+ /// Throws an .
+ ///
+ /// Thrown with no parameters.
+ [DoesNotReturn]
+ private static void Throw()
+ {
+ throw new ObjectDisposedException(null);
+ }
+
+ ///
+ /// Throws an for a given target instance.
+ ///
+ /// The target instance that was disposed.
+ /// Thrown for .
+ [DoesNotReturn]
+ private static void Throw(object targetObject)
+ {
+ throw new ObjectDisposedException(targetObject.ToString());
+ }
+}
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
index e04c8b81..f3fd8190 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
@@ -22,6 +22,7 @@
+
diff --git a/src/ComputeSharp.D2D1.Uwp/CanvasEffect.Interop.cs b/src/ComputeSharp.D2D1.Uwp/CanvasEffect.Interop.cs
index 694bf1a0..4d630cb2 100644
--- a/src/ComputeSharp.D2D1.Uwp/CanvasEffect.Interop.cs
+++ b/src/ComputeSharp.D2D1.Uwp/CanvasEffect.Interop.cs
@@ -1,5 +1,4 @@
using System;
-using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.InteropServices;
using ABI.Microsoft.Graphics.Canvas;
@@ -69,10 +68,7 @@ unsafe partial class CanvasEffect
{
lock (this.lockObject)
{
- if (this.isDisposed)
- {
- ThrowObjectDisposedException();
- }
+ default(ObjectDisposedException).ThrowIf(this.isDisposed, this);
this.canvasImage ??= CreateCanvasImage();
@@ -99,13 +95,4 @@ unsafe partial class CanvasEffect
canvasImageUnknown.CopyTo(canvasImageInterop).Assert();
}
-
- ///
- /// Throws a new .
- ///
- [DoesNotReturn]
- public void ThrowObjectDisposedException()
- {
- throw new ObjectDisposedException(ToString(), "The current effect has been disposed and can no longer be used.");
- }
}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs
index b83600cf..e458491f 100644
--- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs
+++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs
@@ -108,30 +108,30 @@ partial class PixelShaderEffect
bool ICollection.IsSynchronized => true;
///
- object ICollection.SyncRoot => throw new NotSupportedException("ICollection.SyncRoot is not supported for ResourceTextureManagerCollection.");
+ object ICollection.SyncRoot => default(NotSupportedException).Throw