Closed as not planned
Description
Background and Motivation
We designed BinaryData as a simple one-stop shop converting data from and to binary data. This type is especially useful for the Azure SDK where many technologies store blobs of data but the consumer typically uses strings or JSON encoded data.
We've recently added JsonNode
for .NET 6 which includes the ability to treat a JSON object as dynamic
so that one can "dot" into the type without having to use the indexer syntax. The Azure SDK has asked me whether we could add a convenience method to BinaryData
to directly convert a blob to a dynamic object.
Proposed API
namespace System
{
public class BinaryData
{
public dynamic ToDynamicFromJson(JsonSerializerOptions? options = null);
}
}
Usage Examples
Response response = client.SomeMethod("s1", 5, RequestContent.Create(model));
dynamic result = response.Content.ToDynamicFromJson();
Console.WriteLine(result.Baz);
Alternative Designs
The Azure SDK could define their own extension method, but that feels wrong.
Risks
None; BinaryData
already depends on System.Text.Json
. This new API doesn't change the dependency matrix.