Skip to content

Make the C# declaration components authorable - #11598

Draft
Timothee Guerin (timotheeguerin) wants to merge 3 commits into
microsoft:mainfrom
timotheeguerin:ef/csharp-authorable-declarations
Draft

Make the C# declaration components authorable#11598
Timothee Guerin (timotheeguerin) wants to merge 3 commits into
microsoft:mainfrom
timotheeguerin:ef/csharp-authorable-declarations

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

The C# declaration components rendered exactly one shape and dropped anything the caller passed. ClassDeclaration always emitted every property of the model and nothing else, Property accepted three props out of the ~15 Alloy supports, EnumDeclaration always derived its members from the type, and JsonConverter had a fixed body with no way to document it or change its visibility. An emitter that needed a constructor in the class, or a filtered property list, or a differently-named property, had to fork the component.

They now take props:

<ClassDeclaration type={model} properties={visibleProperties} partial>
  <Constructor />
</ClassDeclaration>
  • ClassDeclaration — explicit properties list, extra members as children.
  • Property — the full Alloy property prop set, plus name and csharpType overrides.
  • EnumDeclaration — explicit members list and a jsonAttributes prop.
  • JsonConverterdoc, access modifiers, extra members, an explicit csharpType, and a readReturns override.

Caller-supplied props are spread last so they win over the framework defaults, and every prop is optional, so existing behavior is unchanged.


Part of a 7-PR stack moving @typespec/http-server-csharp onto the emitter framework. Stacked on #11597 — only the last commit is new here.

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.
@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/emitter-framework@11598

commit: 387a153

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter-framework Issues for the emitter framework label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/emitter-framework
Show changes

@typespec/emitter-framework - feature ✏️

Let emitters author the C# declaration components instead of forking them,> ,> - ClassDeclaration accepts an explicit properties list and extra members as children.,> - Property accepts every Alloy property prop, plus name and csharpType overrides.,> - EnumDeclaration accepts an explicit members list and a jsonAttributes prop.,> - JsonConverter accepts doc, access modifiers, extra members, an explicit csharpType, and a readReturns override.,> ,> tsx,> <ClassDeclaration type={model} properties={model.properties.values().filter(isVisible)} partial>,> <Constructor />,> </ClassDeclaration>,>

@typespec/emitter-framework - fix ✏️

Make the C# TypeExpression handle every type kind instead of throwing,> ,> Tuple, StringTemplate, EnumMember, ModelProperty, UnionVariant, template parameters and the full Intrinsic set are now supported, and an unsupported type reports a diagnostic and falls back to object rather than throwing. Also fixes the C# components reporting a TypeScript diagnostic for unsupported scalars, and corrects the C# expressions for the null and never intrinsics.

@typespec/emitter-framework - feature ✏️

Support declaration overrides in Experimental_ComponentOverrides,> ,> Only reference overrides were dispatched, so an emitter could customize how a type is referenced but not how it is declared, forcing it to fork the framework's declaration components. The C# ClassDeclaration, Property and EnumDeclaration now render through the override point.,> ,> tsx,> const overrides = Experimental_ComponentOverridesConfig().forTypeKind("ModelProperty", {,> declaration: (props) =>,> props.type.name === "id" ? (,> <props.Declaration {...props.declarationProps} name="Identifier" />,> ) : (,> props.default,> ),,> });,>

@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter-framework Issues for the emitter framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant