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

Annotate BaseUrl set with MemberNotNull to prevent CS8618. #4739

Merged
merged 2 commits into from
Feb 2, 2024

Conversation

powercode
Copy link
Contributor

Fixes #4704
Generate BaseUrl like this

 public string BaseUrl
 {
     get { return _baseUrl; }
     [System.Diagnostics.CodeAnalysis.MemberNotNull(nameof(_baseUrl))]
     set
     {
         _baseUrl = value;
         if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/"))
             _baseUrl += '/';
     }
 }

This prevents the warning

warning CS8618: Non-nullable field '_baseUrl' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

@RicoSuter RicoSuter merged commit c177153 into RicoSuter:master Feb 2, 2024
1 check passed
@nakrad
Copy link

nakrad commented Mar 11, 2024

This change seems to break .NET Standard 2.0 support.

lahma pushed a commit to lahma/NSwag that referenced this pull request Jun 13, 2024
…#4739)

* Annotate BaseUrl set with MemberNotNull to prevent CS8618.

* Updating generated samples

---------

Co-authored-by: Staffan Gustafsson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NSwag 14.0.1 still issues warning CS8618
3 participants