-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[API Proposal]: Add freezing APIs to JsonTypeInfo #76893
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsBackground and motivationFollowing up on #76540, this tracks the proposal to add user browsable locking APIs for the System.Text.Json metadata types. It follows the API shape applied to API Proposalnamespace System.Text.Json.Metadata;
public partial static class JsonTypeInfo
{
public bool IsReadOnly { get; }
public void MakeReadOnly();
} API Usagevar resolver = new DefaultJsonTypeInfoResolver
{
Modifiers =
{
static typeInfo =>
{
if (typeInfo.IsReadOnly)
{
// type is locked for further modification, exit the modifier
return;
}
if (typeInfo.Type == typeof(MySpecialPoco))
{
typeInfo.CreateObject = () => new MySpecialPoco("defaultValue");
// prevent subsequent modifiers/resolvers from further modifying this contract
typeInfo.MakeReadOnly();
}
}
}
} Alternative DesignsNo response RisksNo response
|
Background and motivation
Following up on #76540, this tracks the proposal to add user browsable locking APIs for the System.Text.Json metadata types. It follows the API shape applied to
JsonSerializerOptions
in #74431.API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: