From fed57d0e61a0c7c3ae3124ae35663a40e836caf1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 12:50:30 +0000 Subject: [PATCH 1/2] Initial plan From 4679242b7eaf3323d5ac72e8339407992978e36b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 12:52:25 +0000 Subject: [PATCH 2/2] Fix ConstructorTemplate zero-arg this() initializer rendering Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com> --- CodeBlocker.Test/TemplateTests.cs | 20 ++++++++++++++++++++ CodeBlocker/Templates/ConstructorTemplate.cs | 10 ++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CodeBlocker.Test/TemplateTests.cs b/CodeBlocker.Test/TemplateTests.cs index 63dc3df..4b809ef 100644 --- a/CodeBlocker.Test/TemplateTests.cs +++ b/CodeBlocker.Test/TemplateTests.cs @@ -420,6 +420,26 @@ public Widget() Render(constructor)); } + [TestMethod] + public void AConstructorCanChainToThisWithNoArguments() + { + ConstructorTemplate constructor = new() + { + Name = "Widget", + Keywords = { "public" }, + Parameters = { new ParameterTemplate { Type = "int", Name = "count" } }, + ChainsToThis = true, + }; + + Assert.AreEqual( + """ + public Widget(int count) + : this() { } + + """.ReplaceLineEndings("\n"), + Render(constructor)); + } + #endregion #region OperatorTemplate diff --git a/CodeBlocker/Templates/ConstructorTemplate.cs b/CodeBlocker/Templates/ConstructorTemplate.cs index 92bdba7..4915a51 100644 --- a/CodeBlocker/Templates/ConstructorTemplate.cs +++ b/CodeBlocker/Templates/ConstructorTemplate.cs @@ -14,14 +14,16 @@ public class ConstructorTemplate : MemberTemplate public Collection Parameters { get; } = []; /// - /// Gets the arguments passed to the base constructor, written verbatim. Empty omits the - /// : base(...) clause entirely. + /// Gets the arguments passed to the constructor initialiser, written verbatim. Empty omits the + /// clause when is and emits : this() + /// when is . /// public Collection BaseParameters { get; } = []; /// /// Gets or sets a value indicating whether the initialiser chains to this rather than - /// base. + /// base. When , an initialiser is always emitted, including the + /// zero-argument form : this(). /// public bool ChainsToThis { get; set; } @@ -49,7 +51,7 @@ public override void WriteTo(CodeBlocker codeBlocker) private void WriteInitialiserTo(CodeBlocker codeBlocker) { - if (BaseParameters.Count == 0) + if (!ChainsToThis && BaseParameters.Count == 0) { return; }