Use Alloy for C# keywords and System.Text.Json symbols - #11599
Use Alloy for C# keywords and System.Text.Json symbols#11599Timothee Guerin (timotheeguerin) wants to merge 4 commits into
Conversation
Adds handling for Tuple, StringTemplate, EnumMember, ModelProperty, UnionVariant, template parameters and the full Intrinsic set. An unsupported type now reports a diagnostic and falls back to `object` instead of throwing. Also fixes the C# components reporting a TypeScript diagnostic for unsupported scalars, and corrects the C# expressions emitted for the `null` and `never` intrinsics. Adds an `isCSharpValueType` util.
…al_ComponentOverrides The `declaration` descriptor existed but nothing dispatched to it, so an emitter could override how a type is referenced but not how it is declared. The C# `ClassDeclaration`, `Property` and `EnumDeclaration` now render through the override point.
ClassDeclaration takes an explicit property list and extra members, Property takes the full Alloy property prop set plus name/csharpType overrides, EnumDeclaration takes an explicit member list and jsonAttributes, and JsonConverter takes doc, access modifiers, extra members and an explicit csharpType.
…xt.Json symbols Deletes the emitter's own C# keyword table and its re-declaration of the System.Text.Json.Serialization attributes, both of which are provided by @alloy-js/csharp. Namespace segments colliding with BCL type names are still renamed, now via a dedicated getCSharpNamespaceName helper.
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
The emitter carried a 217-line hand-maintained table of C# keywords and a
createLibrarycall re-declaring theSystem.Text.Json.Serializationattributes.@alloy-js/csharpships both, and its versions are better: the local keyword list was missingdelegate, and hand-declared symbols do not participate in Alloy's automaticusingmanagement.Both are deleted in favour of the Alloy equivalents (
isValidCSharpIdentifier,csharpKeywords, theSystem/Text/Jsonbuiltins), along with the localgetDocCommentscopy, which is already exported from@typespec/emitter-framework/csharp.One thing Alloy deliberately does not do is worth calling out: its name policy
@-escapes real keywords, but the emitter needs namespace segments colliding with common BCL type names to be renamed — a namespace calledTypeshadowsSystem.Typeand breaks everytypeof()in the generated converters. That rule survives, now isolated ingetCSharpNamespaceNameand built on Alloy's keyword sets rather than a parallel list.Generated output is unchanged.
Part of a 7-PR stack moving
@typespec/http-server-csharponto the emitter framework. Stacked on #11598 — only the last commit is new here.