Skip to content

Extend --with-conditional to multi-file output#774

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-with-conditional-multi-file
Jul 14, 2026
Merged

Extend --with-conditional to multi-file output#774
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-with-conditional-multi-file

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Follow-up to #772, which added --with-conditional for single-file output. This extends the same option to multi-file output: each generated C# file is wrapped in a leading #if <symbol> and trailing #endif using the same single global symbol.

// StructOne.cs
#if VERSION_2_OR_NEWER

namespace Demo.Ns
{
    public partial struct StructOne
    {
        public int x;
    }
}
#endif

Same two choke points as single-file, just in the multi-file writer (CloseOutputBuilder): the #if goes after the header/before the usings, the #endif after the namespace close. Empty-contents builders are already skipped before the writer runs, so every emitted file gets a matched pair.


XML output and per-file (varying) symbols remain out of scope, same as #772 — a per-file symbol wants a remap and is a separate design. The golden-file harness is single-stream, so the multi-file test drives the generator directly with a per-path capturing stream factory (ConditionalMultiFileOutputTest).

Relates to #365

Wraps each file in multi-file C# output in the same leading '#if <symbol>' and trailing '#endif'
using the single global symbol, matching single-file behavior. XML output and per-file symbols
remain out of scope.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit 4effa7d into dotnet:main Jul 14, 2026
14 checks passed
@tannergooding
tannergooding deleted the tannergooding-with-conditional-multi-file branch July 14, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant