Skip to content

Add ReferenceHandler to JsonSourceGenerationOptions - #109174

Merged
eiriktsarpalis merged 5 commits into
dotnet:mainfrom
PranavSenthilnathan:source-gen-ref-handler
Oct 26, 2024
Merged

Add ReferenceHandler to JsonSourceGenerationOptions#109174
eiriktsarpalis merged 5 commits into
dotnet:mainfrom
PranavSenthilnathan:source-gen-ref-handler

Conversation

@PranavSenthilnathan

Copy link
Copy Markdown
Member

Adds a ReferenceHandler property to JsonSourceGenerationOptions to allow users to specify how references are handled when generating source code for JSON types.

Implements #107597

@ghost

ghost commented Oct 24, 2024

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
@ghost

ghost commented Oct 24, 2024

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 24, 2024
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

=> SourceGeneratorHelpers.FormatEnumLiteral(JsonSerializerDefaultsTypeRef, defaults);

private static string FormatReferenceHandler(JsonKnownReferenceHandler referenceHandler)
=> SourceGeneratorHelpers.FormatEnumLiteral(ReferenceHandlerTypeRef, referenceHandler);

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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.

@eiriktsarpalis eiriktsarpalis left a comment

Copy link
Copy Markdown
Member

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 👍

@eiriktsarpalis eiriktsarpalis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eiriktsarpalis
eiriktsarpalis merged commit 3648d83 into dotnet:main Oct 26, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Text.Json community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants