Commit 8b0fcf3
Pass ModelReaderWriterContext in generated TryResolve{Property}Array helpers (#10839)
The `TryResolve{Property}Array` helpers were emitting
`ModelReaderWriter.Write(collection, options)` without the
`ModelReaderWriterContext` argument, breaking AOT-trimmed builds (e.g.
OpenAI) where the context-less overload isn't preserved.
## Changes
- **`ModelReaderWriterOptionsSnippets.cs`**: Added a new
`JsonFormatProperty` snippet that returns the
`ModelReaderWriterOptions.Json` static property.
- **`MrwSerializationTypeDefinition.Dynamic.cs`**: In
`BuildTryResolveArrayMethod`, append
`ModelReaderWriterContextSnippets.Default` to the
`ModelReaderWriter.Write` invocation, mirroring the pattern already used
in `BuildPersistableModelWriteCoreMethodBody` and the XML serialization
path. Also simplified the options argument to use the new
`ModelReaderWriterOptionsSnippets.JsonFormatProperty` snippet instead of
`new ModelReaderWriterOptions("J")`.
- **Test baseline**: Update `PropagateModelListPropertyHelperMethods.cs`
to expect the third argument and the `ModelReaderWriterOptions.Json`
static.
Generated output now matches the rest of the emitter:
```csharp
global::System.BinaryData data = global::System.ClientModel.Primitives.ModelReaderWriter.Write(
ActiveP1(),
global::System.ClientModel.Primitives.ModelReaderWriterOptions.Json,
global::Sample.SampleContext.Default);
```
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>1 parent 90dfcc1 commit 8b0fcf3
4 files changed
Lines changed: 5 additions & 3 deletions
File tree
- packages/http-client-csharp/generator
- Microsoft.TypeSpec.Generator.ClientModel
- src
- Providers
- Snippets
- test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests
- TestProjects/Local/Sample-TypeSpec/src/Generated/Models
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
534 | | - | |
| 534 | + | |
| 535 | + | |
535 | 536 | | |
536 | 537 | | |
537 | 538 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
978 | 978 | | |
979 | 979 | | |
980 | 980 | | |
981 | | - | |
| 981 | + | |
982 | 982 | | |
983 | 983 | | |
984 | 984 | | |
| |||
0 commit comments