-
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
Add ReferenceHandler to JsonSourceGenerationOptions #109174
Add ReferenceHandler to JsonSourceGenerationOptions #109174
Conversation
Note regarding the
|
1 similar comment
Note regarding the
|
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
@@ -1433,6 +1437,9 @@ private static string FormatIgnoreCondition(JsonIgnoreCondition ignoreCondition) | |||
private static string FormatJsonSerializerDefaults(JsonSerializerDefaults defaults) | |||
=> SourceGeneratorHelpers.FormatEnumLiteral(JsonSerializerDefaultsTypeRef, defaults); | |||
|
|||
private static string FormatReferenceHandler(JsonKnownReferenceHandler referenceHandler) | |||
=> SourceGeneratorHelpers.FormatEnumLiteral(ReferenceHandlerTypeRef, referenceHandler); |
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.
Not saying that this wouldn't work, but ReferenceHandler
isn't technically an enum. It's a class with static properties, so perhaps different concerns apply to formatting it?
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.
The default value of the enum didn't map to a default reference handler in the first iteration of this PR. Updated the PR to handle this enum -> reference handler object conversion. Note that for the naming policy, we actually have the policy classes in the Common folder so nameof
works there. I tried to see if I could also move ReferenceHandler
to Common but it has a couple of dependencies so I just left it as it is instead of adding a bunch of types to Common. I just hardcoded the property names for this PR.
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReferenceHandlingStrategy.cs
Outdated
Show resolved
Hide resolved
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.
Left some feedback, but this looks great so far 👍
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.
Thanks!
Adds a
ReferenceHandler
property toJsonSourceGenerationOptions
to allow users to specify how references are handled when generating source code for JSON types.Implements #107597