powertools-lambda-dotnet
powertools-lambda-dotnet copied to clipboard
Maintenance: Enable nullable references across the solution
Summary
C# 8.0 introduced a significant new feature to the language that extends the type system to make a distinction between references that may be null and ones that must not be. Enabling non-nullability is a radical change, which is why the feature is switched off until we enabled it explicitly
Why is this needed?
Nullability becomes an opt-in feature: a reference will never contain null unless it is explicitly defined as a nullable reference. Enabling the type system to distinguish between nullable and non-nullable references is going to be a tricky thing to retrofit. C# cannot always guarantee that a non-nullable reference will never contain a null. However, it can make the guarantee if certain constraints hold, and more generally it will significantly reduce the chances of encountering a NullReferenceException even in cases where it cannot absolutely rule this out.
Which area does this relate to?
Governance
Solution
On each projects .csproj file add inside PropertyGroup
the new tag <Nullable>enable</Nullable>
Example:
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
Acknowledgment
- [X] This request meets Lambda Powertools Tenets