-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make JsonData Immutable #31203
Make JsonData Immutable #31203
Conversation
API change check APIView has identified API level changes in this PR and created following API reviews. |
{ | ||
WriteTo(writer); | ||
} | ||
return new BinaryData(memoryStream.ToArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about?
return new BinaryData(memoryStream.ToArray()); | |
return new BinaryData(memoryStream.GetBuffer().AsMemory(0, (int)stream.Position)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how the BinaryData FromStream method constructs the instance after copying into a separate MemoryStream - https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/System.Memory.Data/src/BinaryData.cs#L179
I think the reason we didn't type sniff for MemoryStream and attempt to extract the ArraySegment is that we wanted the semantics to be consistent across different streams.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsquire, do you know why we implement IDynamicMetaObjectProvider instead of inheriting from DynamicObject?
I can't recall the exact reason, but if I had to hazard a guess, it would be that we didn't want to inherit all of the public methods from |
We're investigating making the JsonData API fully internal, so I revisited this question. It looks like all the There's also the following comment in the DynamicObject reference docs, supporting this hypothesis:
|
Closing in favor of #31769 |
Modifications to JsonData by @jsquire.
Addresses #30717