From 99529c3688a9d704d3c00eba1af00cee8d30a7d5 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 19 Dec 2020 12:54:34 +0100 Subject: [PATCH] Removed ComputeSharp.Core reference from generator --- .../Attributes/ShaderMethodSourceAttribute.cs | 14 ++++++- .../ComputeSharp.Core.csproj | 2 +- .../ComputeSharp.Graphics.csproj | 1 + .../ComputeSharp.SourceGenerators.csproj | 37 +++++++++++++++++-- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/ComputeSharp.Core/Attributes/ShaderMethodSourceAttribute.cs b/src/ComputeSharp.Core/Attributes/ShaderMethodSourceAttribute.cs index 236d9f78..594e01ff 100644 --- a/src/ComputeSharp.Core/Attributes/ShaderMethodSourceAttribute.cs +++ b/src/ComputeSharp.Core/Attributes/ShaderMethodSourceAttribute.cs @@ -5,7 +5,6 @@ using System.Diagnostics.Contracts; using System.Reflection; using ComputeSharp.Core.Extensions; using ComputeSharp.Exceptions; -using Microsoft.Toolkit.Diagnostics; namespace ComputeSharp { @@ -79,7 +78,10 @@ namespace ComputeSharp [Pure] internal static ShaderMethodSourceAttribute GetForDelegate(Delegate function) { - Guard.IsTrue(function.Method.IsStatic, "Captured delegates need to wrap static methods"); + if (!function.Method.IsStatic) + { + ThrowArgumentExceptionForNonStaticShader(); + } var attributes = function.Method.DeclaringType!.Assembly.GetCustomAttributes(); string methodName = function.Method.GetFullName(); @@ -94,5 +96,13 @@ namespace ComputeSharp return MissingMethodSourceException.Throw(function); } + + /// + /// Throws an when a given is not static. + /// + private static void ThrowArgumentExceptionForNonStaticShader() + { + throw new ArgumentException("Captured delegates in a shader need to wrap a static method.", "function"); + } } } \ No newline at end of file diff --git a/src/ComputeSharp.Core/ComputeSharp.Core.csproj b/src/ComputeSharp.Core/ComputeSharp.Core.csproj index deb643c7..17666dbb 100644 --- a/src/ComputeSharp.Core/ComputeSharp.Core.csproj +++ b/src/ComputeSharp.Core/ComputeSharp.Core.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj b/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj index d5fab37a..945a84ec 100644 --- a/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj +++ b/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj @@ -6,6 +6,7 @@ + diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index 467bb2d1..d2b96445 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -10,13 +10,42 @@ false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - -