What's wrong
GeneratorBase.WriteFileHeader (SourceGeneratorToolkit/GeneratorBase.cs:128) writes // {copyright} once. Only the first line of the copyright is commented. The parameter is meant to keep the generated header in step with the consumer's file-header template, and those templates are often more than one line. Nothing rejects a line break. WriteSourceFile goes through the same code.
Repro
WriteFileHeader(codeBlocker, "Copyright (c) Example.\nAll rights reserved.");
codeBlocker.WriteLine("namespace Generated { }");
Output:
// Copyright (c) Example.
All rights reserved.
// <auto-generated />
When compiled with CSharpCompilation this gives 4 errors (CS1003, CS1002, CS0246 'All', …). In a real consumer the error shows up in the generated file rather than at the point where the copyright was configured.
Suggested fix
Split the copyright on \r\n, \n and \r, and write // plus each line, using a bare // for empty lines. If a single line is the intended contract, throw ArgumentException on a line break instead of emitting broken code. Add a test that compiles the header produced from a multi-line copyright.
What's wrong
GeneratorBase.WriteFileHeader(SourceGeneratorToolkit/GeneratorBase.cs:128) writes// {copyright}once. Only the first line of the copyright is commented. The parameter is meant to keep the generated header in step with the consumer's file-header template, and those templates are often more than one line. Nothing rejects a line break.WriteSourceFilegoes through the same code.Repro
Output:
When compiled with
CSharpCompilationthis gives 4 errors (CS1003, CS1002, CS0246 'All', …). In a real consumer the error shows up in the generated file rather than at the point where the copyright was configured.Suggested fix
Split the copyright on
\r\n,\nand\r, and write//plus each line, using a bare//for empty lines. If a single line is the intended contract, throwArgumentExceptionon a line break instead of emitting broken code. Add a test that compiles the header produced from a multi-line copyright.