diff --git a/src/ComputeSharp.SourceGeneration/Extensions/IndentedTextWriterExtensions.cs b/src/ComputeSharp.SourceGeneration/Extensions/IndentedTextWriterExtensions.cs
index 575c1c9d..14ec4e7f 100644
--- a/src/ComputeSharp.SourceGeneration/Extensions/IndentedTextWriterExtensions.cs
+++ b/src/ComputeSharp.SourceGeneration/Extensions/IndentedTextWriterExtensions.cs
@@ -21,7 +21,12 @@ internal static class IndentedTextWriterExtensions
/// The instance to write into.
/// The name of the generator.
/// Whether to use fully qualified type names or not.
- public static void WriteGeneratedAttributes(this IndentedTextWriter writer, string generatorName, bool useFullyQualifiedTypeNames = true)
+ /// Whether to also include the attribute for non-user code.
+ public static void WriteGeneratedAttributes(
+ this IndentedTextWriter writer,
+ string generatorName,
+ bool useFullyQualifiedTypeNames = true,
+ bool includeNonUserCodeAttributes = true)
{
// We can use this class to get the assembly, as all files for generators are just included
// via shared projects. As such, the assembly will be the same as the generator type itself.
@@ -30,14 +35,22 @@ internal static class IndentedTextWriterExtensions
if (useFullyQualifiedTypeNames)
{
writer.WriteLine($$"""[global::System.CodeDom.Compiler.GeneratedCode("{{generatorName}}", "{{assemblyVersion}}")]""");
- writer.WriteLine($$"""[global::System.Diagnostics.DebuggerNonUserCode]""");
- writer.WriteLine($$"""[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]""");
+
+ if (includeNonUserCodeAttributes)
+ {
+ writer.WriteLine($$"""[global::System.Diagnostics.DebuggerNonUserCode]""");
+ writer.WriteLine($$"""[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]""");
+ }
}
else
{
writer.WriteLine($$"""[GeneratedCode("{{generatorName}}", "{{assemblyVersion}}")]""");
- writer.WriteLine($$"""[DebuggerNonUserCode]""");
- writer.WriteLine($$"""[ExcludeFromCodeCoverage]""");
+
+ if (includeNonUserCodeAttributes)
+ {
+ writer.WriteLine($$"""[DebuggerNonUserCode]""");
+ writer.WriteLine($$"""[ExcludeFromCodeCoverage]""");
+ }
}
}