Skip to content

feat(csharp): add options to disable DateOnly and TimeOnly generation for System.Text.Json#2842

Closed
findyoucef wants to merge 5 commits into
glideapps:masterfrom
findyoucef:master
Closed

feat(csharp): add options to disable DateOnly and TimeOnly generation for System.Text.Json#2842
findyoucef wants to merge 5 commits into
glideapps:masterfrom
findyoucef:master

Conversation

@findyoucef

Copy link
Copy Markdown
Contributor

Description

Adds two new C# renderer options to control whether DateOnly and TimeOnly types are emitted when generating System.Text.Json code. Also updates the renderer to conditionally register their converters and refreshes ajv and esbuild dependencies.

Related Issue

#2629

Motivation and Context

Projects targeting .NET Standard lack DateOnly and TimeOnly, causing compilation errors in generated code. This change adds --no-dateonly and --no-timeonly options so users can disable these types for better cross-platform compatibility.

Previous Behaviour / Output

Generated code always included:

public DateOnly StartDate { get; set; }
options.Converters.Add(new DateOnlyConverter());

Which fails on .NET Standard.

New Behaviour / Output

With flags:

quicktype --lang csharp --framework system-text-json --no-dateonly --no-timeonly

Output now omits DateOnly/TimeOnly and related converters:

public DateTime StartDate { get; set; }
// No DateOnlyConverter registration

How Has This Been Tested?

  • Verified .NET 7 (default behavior) and .NET Standard 2.0 (flags enabled) compile successfully.
  • Generated C# code compatible with .NET Standard by disabling unsupported DateOnly/TimeOnly types.

Summary

Adds no-dateonly and no-timeonly C# options for System.Text.Json codegen.

Impact

Allows generating C# code compatible with .NET Standard by disabling unsupported DateOnly/TimeOnly types.

findyoucef and others added 5 commits October 27, 2025 17:32
- Updated package.json dependencies for ajv and esbuild.
- Introduced new boolean options `no-dateonly` and `no-timeonly` in CSharp language options to control the usage of DateOnly and TimeOnly types.
- Refactored SystemTextJsonCSharpRenderer to utilize the new options, allowing for conditional registration of DateOnly and TimeOnly converters.
- Added helper methods to determine whether to use DateOnly and TimeOnly based on the new options.
@schani

schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Thank you @findyoucef for this contribution — the underlying problem (the System.Text.Json renderer's unconditional DateOnlyConverter/TimeOnlyConverter emission breaking compilation on .NET Standard / pre-.NET 6 targets, #2629) is real, and your conditional-emission approach is the right fix.

Unfortunately this branch could no longer be rebased onto master: it conflicts with the C# 8 default work that has landed since, and it carries unrelated dependency churn (package.json/package-lock.json, .vscode) that made the diff unmergeable as-is.

I've opened #2962 as a successor that reimplements the live core of your change on current master, with your authorship credited via a Co-authored-by trailer on the commit. Leaving this PR open for reference until the successor lands.

@schani schani closed this Jul 20, 2026
schani added a commit to tolbon/quicktype that referenced this pull request Jul 20, 2026
….Text.Json)

The System.Text.Json C# renderer unconditionally emits DateOnlyConverter
and TimeOnlyConverter helper classes and registers them in
Converter.Settings.  DateOnly and TimeOnly only exist on .NET 6+, so the
generated code does not compile on .NET Standard or older targets
(issue glideapps#2629).

Add a System.Text.Json-only boolean option,
--[no-]dateonly-timeonly-converters (on by default), that suppresses
both the converter classes and their registration.  Nothing else in the
generated code references them, so suppressed output still compiles and
round-trips; default output is byte-for-byte identical.

The option lives in systemTextJsonCSharpOptions rather than the shared
cSharpOptions, so only the System.Text.Json renderer's typed options
include it; CSharpTargetLanguage.getOptions() now returns the
System.Text.Json superset so the CLI accepts the flag.

Covered by a pinned csharp-SystemTextJson quick-test (unions.json with
the converters suppressed must compile and round-trip) and a unit test
asserting the converter classes' presence by default and absence under
the flag.

Reimplementation of glideapps#2842 by youcefnb (findyoucef); supersedes it.
Fixes glideapps#2629.

Co-authored-by: youcefnb <youcef@colorado.edu>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants