You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EpubReader currently lacks nullable reference type annotations, mostly because it needs to target .NET Framework which locks the C# compiler version to C# 7.3 while nullable reference types require at least C# 8.0. However, there is a way to specify an explicit C# compiler version in csproj file via <LangVersion>x.x</LangVersion> project property. This should work even for .NET Framework and .NET Standard 1.0, as long as the code doesn't use any runtime features of the newer C# compiler. The only downside of this approach is the lack of nullable annotation attributes which require the project using them to NOT have any targets other than .NET Core >= 3, .NET >= 5, or .NET Standard 2.1. This leads to two main consequences:
EpubReader cannot have any utility methods for nullable reference type annotations. For example, instead of creating a custom assertion method:
it will have to copy-paste this check everywhere such assertion is required.
.NET libraries themselves don't have any annotations so even after making a String.IsNullOrEmpty(test) check C# compiler still treats test as potentially null. The only workaround is to add an explicit if (test != null) { ... } check.
However, these downsides seem like reasonable tradeoffs for having nullable reference type annotations in EpubReader and most importantly, they don't affect the consumers of the library in any negative way.
Proposed solution
Switch to C# 10.0 compiler and add nullable reference type annotations for VersOne.Epub assembly.
Description
EpubReader currently lacks nullable reference type annotations, mostly because it needs to target .NET Framework which locks the C# compiler version to C# 7.3 while nullable reference types require at least C# 8.0. However, there is a way to specify an explicit C# compiler version in csproj file via
<LangVersion>x.x</LangVersion>
project property. This should work even for .NET Framework and .NET Standard 1.0, as long as the code doesn't use any runtime features of the newer C# compiler. The only downside of this approach is the lack of nullable annotation attributes which require the project using them to NOT have any targets other than .NET Core >= 3, .NET >= 5, or .NET Standard 2.1. This leads to two main consequences:String.IsNullOrEmpty(test)
check C# compiler still treatstest
as potentiallynull
. The only workaround is to add an explicitif (test != null) { ... }
check.However, these downsides seem like reasonable tradeoffs for having nullable reference type annotations in EpubReader and most importantly, they don't affect the consumers of the library in any negative way.
Proposed solution
Switch to C# 10.0 compiler and add nullable reference type annotations for VersOne.Epub assembly.
Additional context
Documentation: https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references
The text was updated successfully, but these errors were encountered: