diff --git a/assemblySize.include.md b/assemblySize.include.md index f7a1dc14..a8c7a4d2 100644 --- a/assemblySize.include.md +++ b/assemblySize.include.md @@ -2,15 +2,15 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 225.0KB | +217.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netstandard2.1 | 8.5KB | 177.0KB | +168.5KB | +12.0KB | +9.5KB | +9.0KB | +14.0KB | -| net461 | 8.5KB | 231.5KB | +223.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net462 | 7.0KB | 230.0KB | +223.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net47 | 7.0KB | 230.0KB | +223.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 230.0KB | +221.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net472 | 8.5KB | 228.5KB | +220.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net48 | 8.5KB | 228.5KB | +220.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net481 | 8.5KB | 228.5KB | +220.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netstandard2.0 | 8.0KB | 227.5KB | +219.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netstandard2.1 | 8.5KB | 179.5KB | +171.0KB | +12.0KB | +9.5KB | +12.0KB | +14.0KB | +| net461 | 8.5KB | 234.0KB | +225.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net462 | 7.0KB | 232.5KB | +225.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net47 | 7.0KB | 232.5KB | +225.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net471 | 8.5KB | 232.5KB | +224.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net472 | 8.5KB | 231.0KB | +222.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net48 | 8.5KB | 231.0KB | +222.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net481 | 8.5KB | 231.0KB | +222.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | | netcoreapp2.0 | 9.0KB | 208.5KB | +199.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | | netcoreapp2.1 | 9.0KB | 187.0KB | +178.0KB | +12.0KB | +10.0KB | +12.0KB | +17.0KB | | netcoreapp2.2 | 9.0KB | 187.0KB | +178.0KB | +12.0KB | +10.0KB | +12.5KB | +17.0KB | @@ -20,7 +20,7 @@ | net6.0 | 10.0KB | 112.5KB | +102.5KB | +9.5KB | +7.0KB | +512bytes | +3.0KB | | net7.0 | 10.0KB | 85.0KB | +75.0KB | +9.5KB | +5.5KB | +512bytes | +3.5KB | | net8.0 | 9.5KB | 68.5KB | +59.0KB | +8.5KB | | +512bytes | +3.5KB | -| net9.0 | 10.0KB | 34.5KB | +24.5KB | +9.0KB | | +512bytes | +3.5KB | +| net9.0 | 9.5KB | 34.5KB | +25.0KB | +9.0KB | | +512bytes | +3.5KB | | net10.0 | 10.0KB | 22.5KB | +12.5KB | +9.0KB | | +512bytes | +3.5KB | | net11.0 | 10.0KB | 19.0KB | +9.0KB | +9.0KB | | +1.0KB | +4.0KB | @@ -29,15 +29,15 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 340.4KB | +332.4KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | -| netstandard2.1 | 8.5KB | 267.8KB | +259.3KB | +19.7KB | +11.2KB | +14.0KB | +19.7KB | -| net461 | 8.5KB | 347.4KB | +338.9KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | -| net462 | 7.0KB | 345.9KB | +338.9KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | -| net47 | 7.0KB | 345.6KB | +338.6KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | -| net471 | 8.5KB | 345.7KB | +337.2KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | -| net472 | 8.5KB | 343.1KB | +334.6KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | -| net48 | 8.5KB | 343.1KB | +334.6KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | -| net481 | 8.5KB | 343.1KB | +334.6KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | +| netstandard2.0 | 8.0KB | 343.1KB | +335.1KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | +| netstandard2.1 | 8.5KB | 270.5KB | +262.0KB | +19.7KB | +11.2KB | +17.0KB | +19.7KB | +| net461 | 8.5KB | 350.0KB | +341.5KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | +| net462 | 7.0KB | 348.5KB | +341.5KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | +| net47 | 7.0KB | 348.3KB | +341.3KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | +| net471 | 8.5KB | 348.3KB | +339.8KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | +| net472 | 8.5KB | 345.7KB | +337.2KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | +| net48 | 8.5KB | 345.7KB | +337.2KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | +| net481 | 8.5KB | 345.7KB | +337.2KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | | netcoreapp2.0 | 9.0KB | 314.8KB | +305.8KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | | netcoreapp2.1 | 9.0KB | 282.9KB | +273.9KB | +19.7KB | +11.7KB | +17.0KB | +22.7KB | | netcoreapp2.2 | 9.0KB | 282.9KB | +273.9KB | +19.7KB | +11.7KB | +17.5KB | +22.7KB | @@ -47,6 +47,6 @@ | net6.0 | 10.0KB | 168.3KB | +158.3KB | +17.2KB | +8.7KB | +1.1KB | +3.7KB | | net7.0 | 10.0KB | 124.3KB | +114.3KB | +17.1KB | +6.9KB | +1.1KB | +4.2KB | | net8.0 | 9.5KB | 98.7KB | +89.2KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | -| net9.0 | 10.0KB | 50.9KB | +40.9KB | +16.5KB | | +1.1KB | +4.2KB | +| net9.0 | 9.5KB | 50.9KB | +41.4KB | +16.5KB | | +1.1KB | +4.2KB | | net10.0 | 10.0KB | 34.1KB | +24.1KB | +16.5KB | | +1.1KB | +4.2KB | | net11.0 | 10.0KB | 28.7KB | +18.7KB | +16.5KB | | +1.6KB | +4.7KB | diff --git a/readme.md b/readme.md index 43ea8b3f..435dc0e3 100644 --- a/readme.md +++ b/readme.md @@ -68,15 +68,15 @@ This project uses features from the current stable SDK and C# language. As such | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 225.0KB | +217.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netstandard2.1 | 8.5KB | 177.0KB | +168.5KB | +12.0KB | +9.5KB | +9.0KB | +14.0KB | -| net461 | 8.5KB | 231.5KB | +223.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net462 | 7.0KB | 230.0KB | +223.0KB | +9.0KB | +7.0KB | +9.0KB | +14.0KB | -| net47 | 7.0KB | 230.0KB | +223.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 230.0KB | +221.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net472 | 8.5KB | 228.5KB | +220.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net48 | 8.5KB | 228.5KB | +220.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net481 | 8.5KB | 228.5KB | +220.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netstandard2.0 | 8.0KB | 227.5KB | +219.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netstandard2.1 | 8.5KB | 179.5KB | +171.0KB | +12.0KB | +9.5KB | +12.0KB | +14.0KB | +| net461 | 8.5KB | 234.0KB | +225.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net462 | 7.0KB | 232.5KB | +225.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net47 | 7.0KB | 232.5KB | +225.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net471 | 8.5KB | 232.5KB | +224.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net472 | 8.5KB | 231.0KB | +222.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net48 | 8.5KB | 231.0KB | +222.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net481 | 8.5KB | 231.0KB | +222.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | | netcoreapp2.0 | 9.0KB | 208.5KB | +199.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | | netcoreapp2.1 | 9.0KB | 187.0KB | +178.0KB | +12.0KB | +10.0KB | +12.0KB | +17.0KB | | netcoreapp2.2 | 9.0KB | 187.0KB | +178.0KB | +12.0KB | +10.0KB | +12.5KB | +17.0KB | @@ -86,7 +86,7 @@ This project uses features from the current stable SDK and C# language. As such | net6.0 | 10.0KB | 112.5KB | +102.5KB | +9.5KB | +7.0KB | +512bytes | +3.0KB | | net7.0 | 10.0KB | 85.0KB | +75.0KB | +9.5KB | +5.5KB | +512bytes | +3.5KB | | net8.0 | 9.5KB | 68.5KB | +59.0KB | +8.5KB | | +512bytes | +3.5KB | -| net9.0 | 10.0KB | 34.5KB | +24.5KB | +9.0KB | | +512bytes | +3.5KB | +| net9.0 | 9.5KB | 34.5KB | +25.0KB | +9.0KB | | +512bytes | +3.5KB | | net10.0 | 10.0KB | 22.5KB | +12.5KB | +9.0KB | | +512bytes | +3.5KB | | net11.0 | 10.0KB | 19.0KB | +9.0KB | +9.0KB | | +1.0KB | +4.0KB | @@ -95,27 +95,27 @@ This project uses features from the current stable SDK and C# language. As such | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 340.4KB | +332.4KB | +16.9KB | +8.2KB | +14.0KB | +19.2KB | -| netstandard2.1 | 8.5KB | 267.8KB | +259.3KB | +19.9KB | +11.2KB | +14.0KB | +19.7KB | -| net461 | 8.5KB | 347.4KB | +338.9KB | +16.9KB | +8.2KB | +14.0KB | +19.2KB | -| net462 | 7.0KB | 345.9KB | +338.9KB | +16.9KB | +8.7KB | +14.0KB | +19.7KB | -| net47 | 7.0KB | 345.6KB | +338.6KB | +16.9KB | +8.2KB | +14.0KB | +19.2KB | -| net471 | 8.5KB | 345.7KB | +337.2KB | +16.9KB | +8.2KB | +14.0KB | +19.2KB | -| net472 | 8.5KB | 343.1KB | +334.6KB | +16.9KB | +8.2KB | +14.0KB | +19.7KB | -| net48 | 8.5KB | 343.1KB | +334.6KB | +16.9KB | +8.2KB | +14.0KB | +19.7KB | -| net481 | 8.5KB | 343.1KB | +334.6KB | +16.9KB | +8.2KB | +14.0KB | +19.7KB | -| netcoreapp2.0 | 9.0KB | 314.8KB | +305.8KB | +16.9KB | +8.2KB | +14.0KB | +19.2KB | -| netcoreapp2.1 | 9.0KB | 282.9KB | +273.9KB | +19.9KB | +11.7KB | +17.0KB | +22.7KB | -| netcoreapp2.2 | 9.0KB | 282.9KB | +273.9KB | +19.9KB | +11.7KB | +17.5KB | +22.7KB | -| netcoreapp3.0 | 9.5KB | 270.5KB | +261.0KB | +20.4KB | +11.7KB | +14.0KB | +19.7KB | -| netcoreapp3.1 | 9.5KB | 268.9KB | +259.4KB | +16.9KB | +11.2KB | +14.0KB | +19.7KB | -| net5.0 | 9.5KB | 222.7KB | +213.2KB | +16.9KB | +8.2KB | +14.0KB | +19.7KB | -| net6.0 | 10.0KB | 168.3KB | +158.3KB | +17.4KB | +8.7KB | +1.1KB | +3.7KB | -| net7.0 | 10.0KB | 124.3KB | +114.3KB | +17.3KB | +6.9KB | +1.1KB | +4.2KB | -| net8.0 | 9.5KB | 98.7KB | +89.2KB | +16.1KB | +299bytes | +1.1KB | +4.2KB | -| net9.0 | 10.0KB | 50.9KB | +40.9KB | +16.6KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 34.1KB | +24.1KB | +16.6KB | | +1.1KB | +4.2KB | -| net11.0 | 10.0KB | 28.7KB | +18.7KB | +16.6KB | | +1.6KB | +4.7KB | +| netstandard2.0 | 8.0KB | 343.1KB | +335.1KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | +| netstandard2.1 | 8.5KB | 270.5KB | +262.0KB | +19.7KB | +11.2KB | +17.0KB | +19.7KB | +| net461 | 8.5KB | 350.0KB | +341.5KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | +| net462 | 7.0KB | 348.5KB | +341.5KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | +| net47 | 7.0KB | 348.3KB | +341.3KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | +| net471 | 8.5KB | 348.3KB | +339.8KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | +| net472 | 8.5KB | 345.7KB | +337.2KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | +| net48 | 8.5KB | 345.7KB | +337.2KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | +| net481 | 8.5KB | 345.7KB | +337.2KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | +| netcoreapp2.0 | 9.0KB | 314.8KB | +305.8KB | +16.7KB | +8.2KB | +14.0KB | +19.2KB | +| netcoreapp2.1 | 9.0KB | 282.9KB | +273.9KB | +19.7KB | +11.7KB | +17.0KB | +22.7KB | +| netcoreapp2.2 | 9.0KB | 282.9KB | +273.9KB | +19.7KB | +11.7KB | +17.5KB | +22.7KB | +| netcoreapp3.0 | 9.5KB | 270.5KB | +261.0KB | +20.2KB | +11.7KB | +14.0KB | +19.7KB | +| netcoreapp3.1 | 9.5KB | 268.9KB | +259.4KB | +16.7KB | +11.2KB | +14.0KB | +19.7KB | +| net5.0 | 9.5KB | 222.7KB | +213.2KB | +16.7KB | +8.2KB | +14.0KB | +19.7KB | +| net6.0 | 10.0KB | 168.3KB | +158.3KB | +17.2KB | +8.7KB | +1.1KB | +3.7KB | +| net7.0 | 10.0KB | 124.3KB | +114.3KB | +17.1KB | +6.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 98.7KB | +89.2KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | +| net9.0 | 9.5KB | 50.9KB | +41.4KB | +16.5KB | | +1.1KB | +4.2KB | +| net10.0 | 10.0KB | 34.1KB | +24.1KB | +16.5KB | | +1.1KB | +4.2KB | +| net11.0 | 10.0KB | 28.7KB | +18.7KB | +16.5KB | | +1.6KB | +4.7KB | diff --git a/src/Polyfill/XDocumentPolyfill.cs b/src/Polyfill/XDocumentPolyfill.cs index 9e53ae46..55688642 100644 --- a/src/Polyfill/XDocumentPolyfill.cs +++ b/src/Polyfill/XDocumentPolyfill.cs @@ -28,20 +28,23 @@ static partial class XDocumentPolyfill /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xdocument.loadasync?view=net-11.0#system-xml-linq-xdocument-loadasync(system-io-stream-system-xml-linq-loadoptions-system-threading-cancellationtoken) - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xdocument.loadasync?view=net-11.0#system-xml-linq-xdocument-loadasync(system-io-textreader-system-xml-linq-loadoptions-system-threading-cancellationtoken) - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// diff --git a/src/Polyfill/XElementPolyfill.cs b/src/Polyfill/XElementPolyfill.cs index 877fcdf0..aeb6fc5a 100644 --- a/src/Polyfill/XElementPolyfill.cs +++ b/src/Polyfill/XElementPolyfill.cs @@ -28,20 +28,23 @@ static partial class XElementPolyfill /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xelement.loadasync?view=net-11.0#system-xml-linq-xelement-loadasync(system-io-stream-system-xml-linq-loadoptions-system-threading-cancellationtoken) - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xelement.loadasync?view=net-11.0#system-xml-linq-xelement-loadasync(system-io-textreader-system-xml-linq-loadoptions-system-threading-cancellationtoken) - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// diff --git a/src/Split/net461/XDocumentPolyfill.cs b/src/Split/net461/XDocumentPolyfill.cs index e735caf5..1611acf1 100644 --- a/src/Split/net461/XDocumentPolyfill.cs +++ b/src/Split/net461/XDocumentPolyfill.cs @@ -25,18 +25,21 @@ static partial class XDocumentPolyfill /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net461/XElementPolyfill.cs b/src/Split/net461/XElementPolyfill.cs index c05b1794..27208879 100644 --- a/src/Split/net461/XElementPolyfill.cs +++ b/src/Split/net461/XElementPolyfill.cs @@ -25,18 +25,21 @@ static partial class XElementPolyfill /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net462/XDocumentPolyfill.cs b/src/Split/net462/XDocumentPolyfill.cs index e735caf5..1611acf1 100644 --- a/src/Split/net462/XDocumentPolyfill.cs +++ b/src/Split/net462/XDocumentPolyfill.cs @@ -25,18 +25,21 @@ static partial class XDocumentPolyfill /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net462/XElementPolyfill.cs b/src/Split/net462/XElementPolyfill.cs index c05b1794..27208879 100644 --- a/src/Split/net462/XElementPolyfill.cs +++ b/src/Split/net462/XElementPolyfill.cs @@ -25,18 +25,21 @@ static partial class XElementPolyfill /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net47/XDocumentPolyfill.cs b/src/Split/net47/XDocumentPolyfill.cs index e735caf5..1611acf1 100644 --- a/src/Split/net47/XDocumentPolyfill.cs +++ b/src/Split/net47/XDocumentPolyfill.cs @@ -25,18 +25,21 @@ static partial class XDocumentPolyfill /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net47/XElementPolyfill.cs b/src/Split/net47/XElementPolyfill.cs index c05b1794..27208879 100644 --- a/src/Split/net47/XElementPolyfill.cs +++ b/src/Split/net47/XElementPolyfill.cs @@ -25,18 +25,21 @@ static partial class XElementPolyfill /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net471/XDocumentPolyfill.cs b/src/Split/net471/XDocumentPolyfill.cs index e735caf5..1611acf1 100644 --- a/src/Split/net471/XDocumentPolyfill.cs +++ b/src/Split/net471/XDocumentPolyfill.cs @@ -25,18 +25,21 @@ static partial class XDocumentPolyfill /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net471/XElementPolyfill.cs b/src/Split/net471/XElementPolyfill.cs index c05b1794..27208879 100644 --- a/src/Split/net471/XElementPolyfill.cs +++ b/src/Split/net471/XElementPolyfill.cs @@ -25,18 +25,21 @@ static partial class XElementPolyfill /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net472/XDocumentPolyfill.cs b/src/Split/net472/XDocumentPolyfill.cs index e735caf5..1611acf1 100644 --- a/src/Split/net472/XDocumentPolyfill.cs +++ b/src/Split/net472/XDocumentPolyfill.cs @@ -25,18 +25,21 @@ static partial class XDocumentPolyfill /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net472/XElementPolyfill.cs b/src/Split/net472/XElementPolyfill.cs index c05b1794..27208879 100644 --- a/src/Split/net472/XElementPolyfill.cs +++ b/src/Split/net472/XElementPolyfill.cs @@ -25,18 +25,21 @@ static partial class XElementPolyfill /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net48/XDocumentPolyfill.cs b/src/Split/net48/XDocumentPolyfill.cs index e735caf5..1611acf1 100644 --- a/src/Split/net48/XDocumentPolyfill.cs +++ b/src/Split/net48/XDocumentPolyfill.cs @@ -25,18 +25,21 @@ static partial class XDocumentPolyfill /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net48/XElementPolyfill.cs b/src/Split/net48/XElementPolyfill.cs index c05b1794..27208879 100644 --- a/src/Split/net48/XElementPolyfill.cs +++ b/src/Split/net48/XElementPolyfill.cs @@ -25,18 +25,21 @@ static partial class XElementPolyfill /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net481/XDocumentPolyfill.cs b/src/Split/net481/XDocumentPolyfill.cs index e735caf5..1611acf1 100644 --- a/src/Split/net481/XDocumentPolyfill.cs +++ b/src/Split/net481/XDocumentPolyfill.cs @@ -25,18 +25,21 @@ static partial class XDocumentPolyfill /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/net481/XElementPolyfill.cs b/src/Split/net481/XElementPolyfill.cs index c05b1794..27208879 100644 --- a/src/Split/net481/XElementPolyfill.cs +++ b/src/Split/net481/XElementPolyfill.cs @@ -25,18 +25,21 @@ static partial class XElementPolyfill /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/netstandard2.0/XDocumentPolyfill.cs b/src/Split/netstandard2.0/XDocumentPolyfill.cs index e735caf5..1611acf1 100644 --- a/src/Split/netstandard2.0/XDocumentPolyfill.cs +++ b/src/Split/netstandard2.0/XDocumentPolyfill.cs @@ -25,18 +25,21 @@ static partial class XDocumentPolyfill /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/netstandard2.0/XElementPolyfill.cs b/src/Split/netstandard2.0/XElementPolyfill.cs index c05b1794..27208879 100644 --- a/src/Split/netstandard2.0/XElementPolyfill.cs +++ b/src/Split/netstandard2.0/XElementPolyfill.cs @@ -25,18 +25,21 @@ static partial class XElementPolyfill /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/netstandard2.1/XDocumentPolyfill.cs b/src/Split/netstandard2.1/XDocumentPolyfill.cs index e735caf5..1611acf1 100644 --- a/src/Split/netstandard2.1/XDocumentPolyfill.cs +++ b/src/Split/netstandard2.1/XDocumentPolyfill.cs @@ -25,18 +25,21 @@ static partial class XDocumentPolyfill /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/netstandard2.1/XElementPolyfill.cs b/src/Split/netstandard2.1/XElementPolyfill.cs index c05b1794..27208879 100644 --- a/src/Split/netstandard2.1/XElementPolyfill.cs +++ b/src/Split/netstandard2.1/XElementPolyfill.cs @@ -25,18 +25,21 @@ static partial class XElementPolyfill /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/uap10.0/XDocumentPolyfill.cs b/src/Split/uap10.0/XDocumentPolyfill.cs index e735caf5..1611acf1 100644 --- a/src/Split/uap10.0/XDocumentPolyfill.cs +++ b/src/Split/uap10.0/XDocumentPolyfill.cs @@ -25,18 +25,21 @@ static partial class XDocumentPolyfill /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XDocument.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XDocument.Parse(content, options); } /// /// Asynchronously creates a new XDocument and initializes its underlying XML tree using the specified text reader, optionally preserving white space. diff --git a/src/Split/uap10.0/XElementPolyfill.cs b/src/Split/uap10.0/XElementPolyfill.cs index c05b1794..27208879 100644 --- a/src/Split/uap10.0/XElementPolyfill.cs +++ b/src/Split/uap10.0/XElementPolyfill.cs @@ -25,18 +25,21 @@ static partial class XElementPolyfill /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space. /// - public static Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(stream, options)); + using var reader = new StreamReader(stream); + var content = await reader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space. /// - public static Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) + public static async Task LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - return Task.FromResult(XElement.Load(textReader, options)); + var content = await textReader.ReadToEndAsync(); + return XElement.Parse(content, options); } /// /// Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space.