Skip to content

Add expression converter for sample generation#10393

Draft
radhgupta wants to merge 1 commit intomicrosoft:mainfrom
radhgupta:feature/expression-converter
Draft

Add expression converter for sample generation#10393
radhgupta wants to merge 1 commit intomicrosoft:mainfrom
radhgupta:feature/expression-converter

Conversation

@radhgupta
Copy link
Copy Markdown
Member

@radhgupta radhgupta commented Apr 15, 2026

What

Adds ExampleValueExpressionBuilder — converts InputExampleValue + CSharpTypeValueExpression (C# AST nodes). Also adds ExampleParameterValue bridge type. This is M2 of the test/sample generation feature.

How it works

The builder dispatches on CSharpType to produce the correct C# expression:

Input Output
"hello" + string Literal("hello")
"73f4..." + Guid Guid.Parse("73f4...")
"http://..." + Uri new Uri("http://...")
1234 + int Literal(1234)
{...} + BinaryData BinaryData.FromObjectAsJson(new { ... })
[...] + IList<T> new T[] { ... }
"Monday" + DayOfWeek DayOfWeek.Monday

ExampleParameterValue supports two modes — pre-built Expression (for known params like credentials) or raw Value (for spec-provided data needing conversion).

Changes

  • New: ClientModel/src/Providers/Samples/ExampleValueExpressionBuilder.cs
  • New: ClientModel/src/Providers/Samples/ExampleParameterValue.cs
  • New: ClientModel/test/Providers/Samples/ExampleValueExpressionBuilderTests.cs (52 tests)
  • Modified: Input/src/Properties/AssemblyInfo.cs — added InternalsVisibleTo for Generator and ClientModel projects to access internal example subtypes (InputExampleRawValue, etc.)

Design doc

https://gist.github.com/radhgupta/9fee69190f1ac2252a88dd88f99de327

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Apr 15, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 15, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10393

commit: 8368f04

@github-actions
Copy link
Copy Markdown
Contributor

No changes needing a change description found.

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

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant