Added polyfills and simplified preprocessor directives#966
Conversation
Renamed classes and variables, moved Excel data types to own static class, added new values to ExcelContentTypes, Schemas and ExcelFileNames, improved consistency of rels indexing
Changed all directives between `#if NETCOREAPP2_0` and `#if NET8_0` to the simpler `#if NET` to reflect the project's minimum target framework of .NET8
Context, OldXmlReader and NewXmlWriter are now protected instead of private, so that they need to be assigned only in the `SheetStyleBuilderBase` class.
…herever they had been prevoiusly hardcoded
This polyfill, alongside the `StreamConfiguredAsyncDisposable` struct that copies the behaviour of the runtime's `ConfiguredAsyncDisposable` and the `Stream.ConfigureAwait` method that resturns it, allowed for cleaning all of the preprocessor directives that were used throughout whole codebase to dispose synchronously of streams for the netstandard2.0 (which was most of them). This also added the benefit of allowing for their asynchronous disposal in framework versions not expicitly targeted by checking if they implement the `IAsyncDisposable` interface.
…OpenXml to OpenXmlWriter.XmlGeneration
There was a problem hiding this comment.
Code Review
This pull request modernizes the library by centralizing OpenXml constants, simplifying preprocessor directives (often replacing specific version checks with a general #if NET block), and improving asynchronous resource handling through broader use of await using and ConfigureAwait(false). It also introduces several polyfills to enable modern patterns on .NET Standard 2.0. However, the review identified multiple regression risks where the switch to #if NET (covering .NET 5.0+) would break builds on older .NET versions for APIs introduced in .NET 6 or 7, such as Task.WaitAsync, StreamWriter.FlushAsync, and TextReader.ReadLineAsync. Other issues include a potential NullReferenceException in the StreamConfiguredAsyncDisposable polyfill and a missing compatibility check for Stream.CopyToAsync in .NET Standard 2.0.
This PR brings many QOL improvements to improve the readability of the codebase, namely:
Stream.DisposeAsyncpolyfill alongside aStreamConfiguredAsyncDisposable(mirroring the runtimes'sConfiguredAsyncDisposable). This allowed clearing most of the preprocessor directives throughout codebase#if NETCOREAPP2_0and#if NET8_0to the simpler#if NETXDocument.LoadAsyncandXDocument.SaveAsyncpolyfillsSchemasandExcel.Filenames, and substituted them where they had been prevoiusly hardcodedFillTemplatemethod overloads fromOpenXmlTemplater