Context
The Azure SDK for .NET management-plane generator needs to deserialize top-level response bodies and LRO IOperationSource results whose C# type is a framework collection, for example:
- TypeSpec Record -> C# IDictionary<string, BinaryData>
- LRO result Foo[] -> C# IList / IReadOnlyList
These collection interface types cannot be deserialized by calling ModelReaderWriter.Read(...) on the collection type itself because they do not implement IPersistableModel.
Existing behavior
MTG already emits correct collection deserialization loops for generated model properties. For example, generated model serialization uses explicit Dictionary<,> / List<> construction with oreach over JsonElement.EnumerateObject() or EnumerateArray(), then delegates leaf values to type-specific deserialization.
However, that logic appears to live in internal/private model serialization implementation details (for example in MrwSerializationTypeDefinition) and is not exposed as a reusable statement-producing helper.
The public TypeFactory.DeserializeJsonValue(...) API handles a single leaf value expression, but it returns a ValueExpression; it cannot emit the multi-statement collection block needed for top-level collection values (declare, null guard, oreach, assign/return).
Request
Please expose a reusable collection deserialization helper/API that generator extensions can call for arbitrary JSON elements / response bodies, ideally something statement-producing, such as:
csharp IReadOnlyList<MethodBodyStatement> BuildDeserializeJsonValueStatements( CSharpType type, ValueExpression jsonElement, string valueName, out ValueExpression value);
or an equivalent API that supports:
- Dictionary and list/interface collection types.
- Nested collections.
- Delegating leaf values through TypeFactory.DeserializeJsonValue(...) or equivalent existing leaf logic.
- Both top-level response values and generated model property values.
Why
Azure SDK for .NET currently needs a local bridge helper in the management generator to cover this gap for top-level response/LRO collection deserialization. Having this exposed in MTG would avoid duplicating collection deserialization logic in downstream generators and keep behavior aligned with generated model serialization.
Related downstream PR: Azure/azure-sdk-for-net#59628
Context
The Azure SDK for .NET management-plane generator needs to deserialize top-level response bodies and LRO IOperationSource results whose C# type is a framework collection, for example:
These collection interface types cannot be deserialized by calling ModelReaderWriter.Read(...) on the collection type itself because they do not implement IPersistableModel.
Existing behavior
MTG already emits correct collection deserialization loops for generated model properties. For example, generated model serialization uses explicit Dictionary<,> / List<> construction with oreach over JsonElement.EnumerateObject() or EnumerateArray(), then delegates leaf values to type-specific deserialization.
However, that logic appears to live in internal/private model serialization implementation details (for example in MrwSerializationTypeDefinition) and is not exposed as a reusable statement-producing helper.
The public TypeFactory.DeserializeJsonValue(...) API handles a single leaf value expression, but it returns a ValueExpression; it cannot emit the multi-statement collection block needed for top-level collection values (declare, null guard, oreach, assign/return).
Request
Please expose a reusable collection deserialization helper/API that generator extensions can call for arbitrary JSON elements / response bodies, ideally something statement-producing, such as:
csharp IReadOnlyList<MethodBodyStatement> BuildDeserializeJsonValueStatements( CSharpType type, ValueExpression jsonElement, string valueName, out ValueExpression value);or an equivalent API that supports:
Why
Azure SDK for .NET currently needs a local bridge helper in the management generator to cover this gap for top-level response/LRO collection deserialization. Having this exposed in MTG would avoid duplicating collection deserialization logic in downstream generators and keep behavior aligned with generated model serialization.
Related downstream PR: Azure/azure-sdk-for-net#59628