diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectIdProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectIdProperty.Syntax.cs
index a4bc4433..061a20e5 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectIdProperty.Syntax.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectIdProperty.Syntax.cs
@@ -1,11 +1,7 @@
-using System;
-using System.Text;
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.SourceGeneration.Helpers;
-using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
-using Microsoft.CodeAnalysis.Text;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
#pragma warning disable CS0618
@@ -22,13 +18,17 @@ partial class ID2D1ShaderGenerator
/// Creates a instance for the EffectId property.
///
/// The input instance with the effect GUID.
- /// An opaque instance to transform the final tree into text.
/// The resulting instance for the EffectId property.
- public static PropertyDeclarationSyntax GetSyntax(EquatableArray info, out Func fixup)
+ public static PropertyDeclarationSyntax GetSyntax(EquatableArray info)
{
+ // Prepare the initialization text
+ string effectIdLiterals = SyntaxFormattingHelper.BuildByteArrayInitializationExpressionString(info.AsSpan());
+
+ ExpressionSyntax effectIdExpression = ParseExpression($$"""new byte[] { {{effectIdLiterals}} }""");
+
// Create the local declaration:
//
- // global::System.ReadOnlySpan bytes = new byte[] { __EMBEDDED_EFFECT_ID_BYTES };
+ // global::System.ReadOnlySpan bytes = new byte[] { };
LocalDeclarationStatementSyntax guidBytesDeclaration =
LocalDeclarationStatement(
VariableDeclaration(
@@ -37,20 +37,7 @@ partial class ID2D1ShaderGenerator
.AddVariables(
VariableDeclarator(Identifier("bytes"))
.WithInitializer(
- EqualsValueClause(
- ArrayCreationExpression(
- ArrayType(PredefinedType(Token(SyntaxKind.ByteKeyword)))
- .AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList(OmittedArraySizeExpression()))))
- .WithInitializer(
- InitializerExpression(
- SyntaxKind.ArrayInitializerExpression,
- SingletonSeparatedList(IdentifierName("__EMBEDDED_EFFECT_ID_BYTES"))))))));
-
- // Prepare the initialization text
- string effectIdLiterals = SyntaxFormattingHelper.BuildByteArrayInitializationExpressionString(info.AsSpan());
-
- // Set the fixup function
- fixup = tree => SourceText.From(tree.ToFullString().Replace("__EMBEDDED_EFFECT_ID_BYTES", effectIdLiterals), Encoding.UTF8);
+ EqualsValueClause(effectIdExpression))));
// Prepare the return statement:
//
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
index ba63bd0c..5d2fccf7 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
@@ -198,11 +198,10 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
// Generate the EffectId properties
context.RegisterSourceOutput(effectIdInfo, static (context, item) =>
{
- PropertyDeclarationSyntax effectDisplayNameProperty = EffectId.GetSyntax(item.EffectId, out Func fixup);
+ PropertyDeclarationSyntax effectDisplayNameProperty = EffectId.GetSyntax(item.EffectId);
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, effectDisplayNameProperty, skipLocalsInit: false);
- SourceText text = fixup(compilationUnit);
- context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(EffectId)}.g.cs", text);
+ context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(EffectId)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
});
// Get the EffectDisplayName info (hierarchy and effect display name)