-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Support reference type custom converters in source gen #57592
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
Conversation
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsFixes #56864
|
string metadataInitSource = $@"{JsonConverterTypeRef} converter = {typeMetadata.ConverterInstantiationLogic}; | ||
if (typeMetadata.IsValueType) | ||
{ | ||
metadataInitSource = $@"{JsonConverterTypeRef} converter = {typeMetadata.ConverterInstantiationLogic}; | ||
{TypeTypeRef} typeToConvert = typeof({typeCompilableName}); | ||
if (!converter.CanConvert(typeToConvert)) | ||
{{ |
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.
Nit: given that there is a some amount of duplication between the ref type and value type generated code, is there any way we could splice in the nullable check, i.e some thing like
if (!converter.CanConvert(typeToConvert))
{{
{!typeof(T).IsValueType ? "" : EmitNullableTypeHandling()}
?
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.
That is a fair suggestion, and I'll leave it up to @layomia to change it if desired. However, in this case I think it is more readable\understandable to have separate if
s since the amount of emit duplication is only 5 LOC or so.
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.
LGTM!
/backport to release/6.0 |
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1148393523 |
/backport to release/6.0-rc1 |
Started backporting to release/6.0-rc1: https://github.com/dotnet/runtime/actions/runs/1159663823 |
Fixes #56864
Expect this to be ported to https://github.com/dotnet/runtime/tree/release/6.0