From b5ff0ee6fdc8b67a005e8edc0732b626e514e49b Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 29 Apr 2026 17:29:07 +0200 Subject: [PATCH] Document whitespace-suppression behavior on CodeBlock.WriteLine and AddBlock WriteLine("") and AddBlock(emptyBlock) are intentionally no-ops: it lets callers interpolate possibly-empty values without producing stray blank lines (e.g. WriteLine(\$\" {body.Indent()}\") with empty body). Vertical whitespace in final output is managed by ToString, which collapses runs of blank lines to at most one. Adds on both methods so the design intent is visible to callers who might otherwise expect WriteLine("") to emit a blank line. --- src/ZeroC.CodeBuilder/CodeBlock.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ZeroC.CodeBuilder/CodeBlock.cs b/src/ZeroC.CodeBuilder/CodeBlock.cs index ada9ae4561..2b7ca2f5e5 100644 --- a/src/ZeroC.CodeBuilder/CodeBlock.cs +++ b/src/ZeroC.CodeBuilder/CodeBlock.cs @@ -46,6 +46,9 @@ public CodeBlock() /// Adds another code block to this one, separated by newlines. /// The block to add. + /// Adding an empty has no effect — no phantom blank-line gap is + /// inserted. The vertical whitespace between non-empty blocks is normalized by , + /// which collapses runs of blank lines to at most one. public void AddBlock(CodeBlock block) => Write($"\n{block}\n"); /// Creates a new code block with the content indented by 4 spaces. @@ -103,5 +106,11 @@ public void Write(string value) /// Writes the specified value followed by a newline to the code block. /// The value to write. + /// drops empty and whitespace-only strings, so WriteLine("") + /// and WriteLine(" ") are no-ops. This is intentional: it lets callers interpolate values + /// that may be empty without producing stray blank lines (for example + /// WriteLine($" {body.Indent()}") when body is empty). Vertical whitespace in the + /// final output is managed by , which collapses runs of blank lines to at + /// most one. public void WriteLine(string value) => Write($"{value}\n"); }