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 API reference types for nullable awareness #176

Merged
merged 2 commits into from Jan 2, 2022

Conversation

pleonex
Copy link
Member

@pleonex pleonex commented Jan 2, 2022

Description

Introduced with C# 8.0, we can annotate the code to specify if a reference-type variable can be null or not. Then, we can enable a new static analysis check that check for potential code paths that will de-reference a null pointer, throwing a NullReferenceException.
Annotating the API allows user to enable the feature as well and ensure a safe usage of the code. Fix all the related warnings

This is introducing the following breaking changes:

  • TextDataReader will not return null string if it starts reading from the end already. It will throw EndOfStreamException.
  • Po initializes an empty header.
  • Properties of PoHeader are initialized to an empty string instead of null values, CreationDate is set to current time.
  • The setter of Po.Header will not check if the header has some required non-empty properties.
  • Po2Binary will write the PO header only if ProjectIdVersion is non-empty instead of checking if the Header property is null.

Example

To enable the feature in any user project, just set <Nullable>enable</Nullable> in the csproj.

@pleonex pleonex added this to the vNext milestone Jan 2, 2022
@pleonex pleonex self-assigned this Jan 2, 2022
@pleonex pleonex merged commit 4d2507a into develop Jan 2, 2022
@pleonex pleonex deleted the feature/nullable branch January 2, 2022 23:49
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.

None yet

1 participant