feat(csharp): add options to disable DateOnly and TimeOnly generation for System.Text.Json#2842
feat(csharp): add options to disable DateOnly and TimeOnly generation for System.Text.Json#2842findyoucef wants to merge 5 commits into
Conversation
- 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.
|
Thank you @findyoucef for this contribution — the underlying problem (the System.Text.Json renderer's unconditional 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 ( I've opened #2962 as a successor that reimplements the live core of your change on current master, with your authorship credited via a |
….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>
Description
Adds two new C# renderer options to control whether
DateOnlyandTimeOnlytypes are emitted when generating System.Text.Json code. Also updates the renderer to conditionally register their converters and refreshesajvandesbuilddependencies.Related Issue
#2629
Motivation and Context
Projects targeting .NET Standard lack
DateOnlyandTimeOnly, causing compilation errors in generated code. This change adds--no-dateonlyand--no-timeonlyoptions so users can disable these types for better cross-platform compatibility.Previous Behaviour / Output
Generated code always included:
Which fails on .NET Standard.
New Behaviour / Output
With flags:
Output now omits
DateOnly/TimeOnlyand related converters:How Has This Been Tested?
DateOnly/TimeOnlytypes.Summary
Adds
no-dateonlyandno-timeonlyC# options for System.Text.Json codegen.Impact
Allows generating C# code compatible with .NET Standard by disabling unsupported
DateOnly/TimeOnlytypes.