WeihanLi.Npoi 1.14.0 Release Notes


WeihanLi.Npoi 1.14.0 Release Notes


Over the weekend, I updated the project, started using nullable reference types, and removed themnet45Support for, support onlynetstandard2.0


Remove net45 Support

The base library is going to be removednet45Because of many basic APIs, thenetstandard2.0Yes, there are, butnet45No, for exampleArray.Empty/Task.CompletedResultSo a lot of time we need to work for themnet45Write some special code to achieve similar functions, and with more and more developers of. Net core,. Net core is becoming more and more mature, so I plan to abandon itnet45It can also make the maintenance more convenient and simple.

Nullable Reference

The new version is fully enabledNullable Reference TypesNullable reference type. One of the reasons why nullable reference type is enabled is to provide better experience for developers. Developers can know whether their API input parameters are allowed to be null when they are developingnull, if not allowednullDevelopers can check before calling the APInullTo avoid entering an unexpectednullFor the return value of an API, it will be clearer to see whether the return value of an API will benull, ifnullYou may need to short check, if notnullThere is no need to do unnecessary empty checks.


A sample project is provided. The sample project is a dotnet core 3.1 project, and the project does not enable nullable reference type. The following is a sample code:

var workbook = ExcelHelper.LoadExcel(excelPath:null);

if (workbook is null)
    Console.WriteLine("workbook is null");

IWorkbook ExcelHelper.LoadExcel(string excelPath)The input parameter of this API expects a non null reference type, and the return value is a non null reference type. Although the sample project does not enable nullable reference types, vs will also give some hints, as follows:

If anullWhat happens to the value passed to a non nullable reference type depends on the processing of the implementation code. As I mentioned in the previous article, when the expected input value is a non nullable reference type, I still need to do the necessary null check. In the actual transformation, I do the same thing. If a non nullable reference type receives a null checknullBasically, you’ll get oneArgumentNullException

The output of the above code execution result is as follows:


It can be seen from the above example that nullable reference type can bring us great convenience, and it can also increase the robustness of the program. Through vs prompt, enabling nullable type can promote the prompt to warning Better improve the reliability of the code, can also reduce a lot of unnecessary null check, by enabling nullable reference type, also let me repair some of the original code missing check, further enhance the robustness of the code.

The sample code can be downloaded fromhttps://github.com/WeihanLi/SamplesInPractice/blob/master/NPOISample/NPOIExtensionSample.csIt can be tested by itself