Skip to content
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

Cast result to nullable type for response data #3929 #5108

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ogazioglu
Copy link

@ogazioglu ogazioglu commented Feb 17, 2025

When nullable annotations are enabled and GenerateNullableReferenceTypes is true, the code below is generated and causes following compiler warning :

Actual Generated Code:

var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string));

Compiler Warning:

warning CS8600: Converting null literal or possible null value to non-nullable type.

But in this configuration, it should be generated as below:

Expected Generated Code:

var result_ = (string?)System.Convert.ChangeType(responseData_, typeof(string));

This fix correctly generates code and resolves the compiler warning.

@ogazioglu ogazioglu marked this pull request as draft March 19, 2025 11:03
@ogazioglu ogazioglu marked this pull request as ready for review March 19, 2025 11:07
@RicoSuter
Copy link
Owner

Is there a fix without using ? NRT as the generator should also work with pre-NRT C# versions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants