From 2f73e70fd2687bc3e3b0e51d468133ab4b0229a6 Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Mon, 20 Jul 2026 17:50:23 -0400 Subject: [PATCH] fix(csharp): make generated Serialize/Converter classes partial (#1520) Co-Authored-By: gpt-5.6-sol via pi --- .../CSharp/NewtonSoftCSharpRenderer.ts | 4 +-- .../CSharp/SystemTextJsonCSharpRenderer.ts | 4 +-- .../csharp-SystemTextJson/Issue1520.cs | 6 ++++ test/fixtures/csharp/Issue1520.cs | 6 ++++ test/unit/csharp-partial-helpers.test.ts | 35 +++++++++++++++++++ 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/csharp-SystemTextJson/Issue1520.cs create mode 100644 test/fixtures/csharp/Issue1520.cs create mode 100644 test/unit/csharp-partial-helpers.test.ts diff --git a/packages/quicktype-core/src/language/CSharp/NewtonSoftCSharpRenderer.ts b/packages/quicktype-core/src/language/CSharp/NewtonSoftCSharpRenderer.ts index b4aebaf7a2..fe348fe9f3 100644 --- a/packages/quicktype-core/src/language/CSharp/NewtonSoftCSharpRenderer.ts +++ b/packages/quicktype-core/src/language/CSharp/NewtonSoftCSharpRenderer.ts @@ -408,7 +408,7 @@ export class NewtonsoftCSharpRenderer extends CSharpRenderer { this.emitType( undefined, AccessModifier.Public, - "static class", + "static partial class", "Serialize", undefined, () => { @@ -471,7 +471,7 @@ export class NewtonsoftCSharpRenderer extends CSharpRenderer { this.emitType( undefined, AccessModifier.Internal, - "static class", + "static partial class", converterName, undefined, () => { diff --git a/packages/quicktype-core/src/language/CSharp/SystemTextJsonCSharpRenderer.ts b/packages/quicktype-core/src/language/CSharp/SystemTextJsonCSharpRenderer.ts index f3eccc8df4..79bf6fa2d5 100644 --- a/packages/quicktype-core/src/language/CSharp/SystemTextJsonCSharpRenderer.ts +++ b/packages/quicktype-core/src/language/CSharp/SystemTextJsonCSharpRenderer.ts @@ -413,7 +413,7 @@ export class SystemTextJsonCSharpRenderer extends CSharpRenderer { this.emitType( undefined, AccessModifier.Public, - "static class", + "static partial class", "Serialize", undefined, () => { @@ -484,7 +484,7 @@ export class SystemTextJsonCSharpRenderer extends CSharpRenderer { this.emitType( undefined, AccessModifier.Internal, - "static class", + "static partial class", converterName, undefined, () => { diff --git a/test/fixtures/csharp-SystemTextJson/Issue1520.cs b/test/fixtures/csharp-SystemTextJson/Issue1520.cs new file mode 100644 index 0000000000..f288194daf --- /dev/null +++ b/test/fixtures/csharp-SystemTextJson/Issue1520.cs @@ -0,0 +1,6 @@ +namespace QuickType +{ + // Simulates partial helper declarations from another generated file. + public static partial class Serialize { } + internal static partial class Converter { } +} diff --git a/test/fixtures/csharp/Issue1520.cs b/test/fixtures/csharp/Issue1520.cs new file mode 100644 index 0000000000..f288194daf --- /dev/null +++ b/test/fixtures/csharp/Issue1520.cs @@ -0,0 +1,6 @@ +namespace QuickType +{ + // Simulates partial helper declarations from another generated file. + public static partial class Serialize { } + internal static partial class Converter { } +} diff --git a/test/unit/csharp-partial-helpers.test.ts b/test/unit/csharp-partial-helpers.test.ts new file mode 100644 index 0000000000..9f472a6e36 --- /dev/null +++ b/test/unit/csharp-partial-helpers.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, test } from "vitest"; + +import { + InputData, + type RendererOptions, + jsonInputForTargetLanguage, + quicktype, +} from "quicktype-core"; + +async function cSharpFor(framework: string): Promise { + const jsonInput = jsonInputForTargetLanguage("csharp"); + await jsonInput.addSource({ + name: "Something", + samples: ['{"some_property":"hello"}'], + }); + const inputData = new InputData(); + inputData.addInput(jsonInput); + const rendererOptions = { framework } as RendererOptions; + const result = await quicktype({ + inputData, + lang: "csharp", + rendererOptions, + }); + return result.lines.join("\n"); +} + +describe("C# helper classes", () => { + for (const framework of ["NewtonSoft", "SystemTextJson"]) { + test(`${framework} helpers are partial`, async () => { + const output = await cSharpFor(framework); + expect(output).toContain("public static partial class Serialize"); + expect(output).toContain("internal static partial class Converter"); + }); + } +});