[dotnet] Emit V2 PropagateGet pattern to support JsonPatch.EnumerateArray on CLR arrays#9957
Draft
[dotnet] Emit V2 PropagateGet pattern to support JsonPatch.EnumerateArray on CLR arrays#9957
Conversation
…rt on CLR arrays Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update generator to support V2 PropagateGet pattern for JsonPatch
[dotnet] Emit V2 PropagateGet pattern to support JsonPatch.EnumerateArray on CLR arrays
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The generated
PropagateGetmethod returnedfalsefor array-level JSON paths (e.g.,$.properties.items) on CLR-backed list properties, makingJsonPatch.EnumerateArraynon-functional for those paths. Only indexed paths ($.properties.items[0]) were handled.Changes
Generator logic (
MrwSerializationTypeDefinition.Dynamic.cs)IsEmptycheck before the firstTryGetIndexcall inBuildCollectionIfStatements— only for outermost list/array properties whose direct element type is a dynamic model (nested collections likeList<List<T>>are intentionally excluded sinceModelReaderWriter.Writedoes not supportIEnumerable<IList<T>>)BuildTryResolveArrayMethod: generatesTryResolve{PropertyName}Array(out EncodedValue)— serializes active CLR items viaModelReaderWriter.Write+ a temporaryJsonPatchBuildActiveItemsMethod: generatesActive{PropertyName}()— yields items where!item.Patch.IsRemoved("$"u8)IsDirectDynamicListProperty/GetQualifyingDynamicListPropertieshelpersMethod registration (
MrwSerializationTypeDefinition.cs)TryResolve{PropertyName}Array+Active{PropertyName}inBuildMethods()for each qualifying collection propertyGenerated output delta
Before (V1):
After (V2):
Original prompt
This section details on the original issue you should resolve
<issue_title>[dotnet] Generator should emit V2 PropagateGet pattern to support JsonPatch.EnumerateArray on CLR arrays</issue_title>
<issue_description>## Summary
The dotnet generator needs to update the code it produces for
PropagateGetmethods on models that have array/collection properties backed by CLR types (e.g.,IList<T>,IReadOnlyList<T>, arrays). Currently the generatedPropagateGetonly handles indexed paths (e.g.,$.properties.virtualMachines[0].id) but returnsfalsefor non-indexed array-level paths (e.g.,$.properties.virtualMachines). This preventsJsonPatch.EnumerateArrayfrom working on CLR-backed collections.Context
PR Azure/azure-sdk-for-net#56826 added the
JsonPatch.EnumerateArrayAPI to System.ClientModel. This API iterates over JSON array elements at a given path, yielding each element asReadOnlyMemory<byte>. For this to work, thePropagateGetcallback registered viaJsonPatch.SetPropagatorsmust be able to resolve array-level paths — not just indexed element paths.That PR includes a hand-written
AvailabilitySetDataV2test model demonstrating the required "v2" pattern alongside the existing "v1"AvailabilitySetDatamodel.What changed: V1 → V2 PropagateGet
The only behavioral difference between V1 and V2 is in
PropagateGet. Everything else (PropagateSet, Deserialize, Serialize structure, constructor, properties) is identical.V1 (current generator output)
V2 (what the generator should produce)
Plus these supporting methods per array property:
Why this matters
Without the V2 pattern,
JsonPatch.EnumerateArray("$.properties.virtualMachines"u8)cannot resolve the array from CLR data when no patch-level replacement exists at that path. The propagator returnsfalse, soEnumerateArrayhas no array data to iterate over.What the generator needs to do
For every collection/array property that has a
PropagateGetbranch:indexSlice.IsEmptycheck before theTryGetIndexcallTryResolve{PropertyName}Arraymethod that serializes the active (non-removed) CLR items viaModelReaderWriter.Writeand returns the result as anEncodedValueActive{PropertyName}iterator...✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.