From 693390636e63c65cc7f50e123faef6a14a2bf43f Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Wed, 3 Dec 2025 18:53:23 +0200 Subject: [PATCH 1/2] Add polyfills for `Stream.DiposeAsync()`, `TextReader.DisposeAsync(...)`, `TextWriter.DisposeAsync(...)` --- PolyShim/NetCore30/Stream.cs | 33 ++++++++++++++++++++++++++++++++ PolyShim/NetCore30/TextReader.cs | 33 ++++++++++++++++++++++++++++++++ PolyShim/NetCore30/TextWriter.cs | 33 ++++++++++++++++++++++++++++++++ PolyShim/Signatures.md | 10 ++++++++-- 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 PolyShim/NetCore30/Stream.cs create mode 100644 PolyShim/NetCore30/TextReader.cs create mode 100644 PolyShim/NetCore30/TextWriter.cs diff --git a/PolyShim/NetCore30/Stream.cs b/PolyShim/NetCore30/Stream.cs new file mode 100644 index 0000000..668f110 --- /dev/null +++ b/PolyShim/NetCore30/Stream.cs @@ -0,0 +1,33 @@ +#if (NETCOREAPP && !NETCOREAPP3_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER) +#nullable enable +// ReSharper disable RedundantUsingDirective +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +// ReSharper disable PartialTypeWithSinglePart + +using System; +using System.IO; +using System.Threading.Tasks; + +internal static partial class PolyfillExtensions +{ + extension(Stream stream) + { +#if FEATURE_TASK + // https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync + public async Task DisposeAsync() + { +#if FEATURE_ASYNCINTERFACES + if (stream is IAsyncDisposable asyncDisposable) + { + await asyncDisposable.DisposeAsync(); + return; + } +#endif + + await Task.Run(stream.Dispose); + } +#endif + } +} +#endif diff --git a/PolyShim/NetCore30/TextReader.cs b/PolyShim/NetCore30/TextReader.cs new file mode 100644 index 0000000..34776c2 --- /dev/null +++ b/PolyShim/NetCore30/TextReader.cs @@ -0,0 +1,33 @@ +#if (NETCOREAPP && !NETCOREAPP3_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER) +#nullable enable +// ReSharper disable RedundantUsingDirective +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +// ReSharper disable PartialTypeWithSinglePart + +using System; +using System.IO; +using System.Threading.Tasks; + +internal static partial class PolyfillExtensions +{ + extension(TextReader reader) + { +#if FEATURE_TASK + // https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync + public async Task DisposeAsync() + { +#if FEATURE_ASYNCINTERFACES + if (reader is IAsyncDisposable asyncDisposable) + { + await asyncDisposable.DisposeAsync(); + return; + } +#endif + + await Task.Run(reader.Dispose); + } +#endif + } +} +#endif diff --git a/PolyShim/NetCore30/TextWriter.cs b/PolyShim/NetCore30/TextWriter.cs new file mode 100644 index 0000000..04844ae --- /dev/null +++ b/PolyShim/NetCore30/TextWriter.cs @@ -0,0 +1,33 @@ +#if (NETCOREAPP && !NETCOREAPP3_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER) +#nullable enable +// ReSharper disable RedundantUsingDirective +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +// ReSharper disable PartialTypeWithSinglePart + +using System; +using System.IO; +using System.Threading.Tasks; + +internal static partial class PolyfillExtensions +{ + extension(TextWriter writer) + { +#if FEATURE_TASK + // https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync + public async Task DisposeAsync() + { +#if FEATURE_ASYNCINTERFACES + if (writer is IAsyncDisposable asyncDisposable) + { + await asyncDisposable.DisposeAsync(); + return; + } +#endif + + await Task.Run(writer.Dispose); + } +#endif + } +} +#endif diff --git a/PolyShim/Signatures.md b/PolyShim/Signatures.md index 71c19e0..1f5a9da 100644 --- a/PolyShim/Signatures.md +++ b/PolyShim/Signatures.md @@ -1,8 +1,8 @@ # Signatures -- **Total:** 333 +- **Total:** 337 - **Types:** 74 -- **Members:** 259 +- **Members:** 263 ___ @@ -318,6 +318,7 @@ ___ - [`int Read(Span)`](https://learn.microsoft.com/dotnet/api/system.io.stream.read#system-io-stream-read(system-span((system-byte)))) .NET Core 2.1 - [`int ReadAtLeast(Span, int, bool)`](https://learn.microsoft.com/dotnet/api/system.io.stream.readatleast) .NET 7.0 - [`Task CopyToAsync(Stream, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.io.stream.copytoasync#system-io-stream-copytoasync(system-io-stream-system-threading-cancellationtoken)) .NET Core 2.1 + - [`Task DisposeAsync()`](https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync) .NET Core 3.0 - [`Task ReadExactlyAsync(byte[], int, int, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.io.stream.readexactlyasync#system-io-stream-readexactlyasync(system-byte()-system-int32-system-int32-system-threading-cancellationtoken)) .NET 7.0 - [`Task ReadExactlyAsync(Memory, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.io.stream.readexactlyasync#system-io-stream-readexactlyasync(system-memory((system-byte))-system-threading-cancellationtoken)) .NET 7.0 - [`Task WriteAsync(ReadOnlyMemory, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.io.stream.writeasync#system-io-stream-writeasync(system-readonlymemory((system-byte))-system-threading-cancellationtoken)) .NET Core 2.1 @@ -395,6 +396,7 @@ ___ - [`Task WaitAsync(TimeSpan)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.waitasync#system-threading-tasks-task-waitasync(system-timespan)) .NET 6.0 - [`Task WhenAll(IEnumerable)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.whenall#system-threading-tasks-task-whenall(system-collections-generic-ienumerable((system-threading-tasks-task)))) .NET Core 1.0 - [`Task WhenAll(params Task[])`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.whenall#system-threading-tasks-task-whenall(system-threading-tasks-task())) .NET Core 1.0 + - [`Task Yield()`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.yield) .NET Core 1.0 - [`Task FromResult(T?)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.fromresult) .NET Core 1.0 - [`Task WhenAll(IEnumerable>)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.whenall#system-threading-tasks-task-whenall-1(system-collections-generic-ienumerable((system-threading-tasks-task((-0)))))) .NET Core 1.0 - [`Task WhenAll(params Task[])`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.whenall#system-threading-tasks-task-whenall-1(system-threading-tasks-task((-0))())) .NET Core 1.0 @@ -415,6 +417,10 @@ ___ - `TaskCompletionSource` - [`bool TrySetCanceled(CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.taskcompletionsource-1.trysetcanceled#system-threading-tasks-taskcompletionsource-1-trysetcanceled(system-threading-cancellationtoken)) .NET Core 1.0 - [`void SetCanceled(CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.taskcompletionsource-1.setcanceled#system-threading-tasks-taskcompletionsource-1-setcanceled(system-threading-cancellationtoken)) .NET 5.0 +- `TextReader` + - [`Task DisposeAsync()`](https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync) .NET Core 3.0 +- `TextWriter` + - [`Task DisposeAsync()`](https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync) .NET Core 3.0 - `ThreadAbortException` - [**[class]**](https://learn.microsoft.com/dotnet/api/system.threading.threadabortexception) .NET Core 2.0 - `TimeSpan` From 3a8fcf8a09746b2e4e829658d5403f9c0f7e4d9c Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Wed, 3 Dec 2025 18:58:24 +0200 Subject: [PATCH 2/2] asd --- PolyShim/NetCore30/TextReader.cs | 2 +- PolyShim/NetCore30/TextWriter.cs | 2 +- PolyShim/Signatures.md | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/PolyShim/NetCore30/TextReader.cs b/PolyShim/NetCore30/TextReader.cs index 34776c2..cd552b3 100644 --- a/PolyShim/NetCore30/TextReader.cs +++ b/PolyShim/NetCore30/TextReader.cs @@ -14,7 +14,7 @@ internal static partial class PolyfillExtensions extension(TextReader reader) { #if FEATURE_TASK - // https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync + // https://learn.microsoft.com/dotnet/api/system.io.textreader.disposeasync public async Task DisposeAsync() { #if FEATURE_ASYNCINTERFACES diff --git a/PolyShim/NetCore30/TextWriter.cs b/PolyShim/NetCore30/TextWriter.cs index 04844ae..97d9ca9 100644 --- a/PolyShim/NetCore30/TextWriter.cs +++ b/PolyShim/NetCore30/TextWriter.cs @@ -14,7 +14,7 @@ internal static partial class PolyfillExtensions extension(TextWriter writer) { #if FEATURE_TASK - // https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync + // https://learn.microsoft.com/dotnet/api/system.io.textwriter.disposeasync public async Task DisposeAsync() { #if FEATURE_ASYNCINTERFACES diff --git a/PolyShim/Signatures.md b/PolyShim/Signatures.md index 1f5a9da..6e6e827 100644 --- a/PolyShim/Signatures.md +++ b/PolyShim/Signatures.md @@ -1,8 +1,8 @@ # Signatures -- **Total:** 337 +- **Total:** 336 - **Types:** 74 -- **Members:** 263 +- **Members:** 262 ___ @@ -396,7 +396,6 @@ ___ - [`Task WaitAsync(TimeSpan)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.waitasync#system-threading-tasks-task-waitasync(system-timespan)) .NET 6.0 - [`Task WhenAll(IEnumerable)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.whenall#system-threading-tasks-task-whenall(system-collections-generic-ienumerable((system-threading-tasks-task)))) .NET Core 1.0 - [`Task WhenAll(params Task[])`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.whenall#system-threading-tasks-task-whenall(system-threading-tasks-task())) .NET Core 1.0 - - [`Task Yield()`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.yield) .NET Core 1.0 - [`Task FromResult(T?)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.fromresult) .NET Core 1.0 - [`Task WhenAll(IEnumerable>)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.whenall#system-threading-tasks-task-whenall-1(system-collections-generic-ienumerable((system-threading-tasks-task((-0)))))) .NET Core 1.0 - [`Task WhenAll(params Task[])`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.whenall#system-threading-tasks-task-whenall-1(system-threading-tasks-task((-0))())) .NET Core 1.0 @@ -418,9 +417,9 @@ ___ - [`bool TrySetCanceled(CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.taskcompletionsource-1.trysetcanceled#system-threading-tasks-taskcompletionsource-1-trysetcanceled(system-threading-cancellationtoken)) .NET Core 1.0 - [`void SetCanceled(CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.threading.tasks.taskcompletionsource-1.setcanceled#system-threading-tasks-taskcompletionsource-1-setcanceled(system-threading-cancellationtoken)) .NET 5.0 - `TextReader` - - [`Task DisposeAsync()`](https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync) .NET Core 3.0 + - [`Task DisposeAsync()`](https://learn.microsoft.com/dotnet/api/system.io.textreader.disposeasync) .NET Core 3.0 - `TextWriter` - - [`Task DisposeAsync()`](https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync) .NET Core 3.0 + - [`Task DisposeAsync()`](https://learn.microsoft.com/dotnet/api/system.io.textwriter.disposeasync) .NET Core 3.0 - `ThreadAbortException` - [**[class]**](https://learn.microsoft.com/dotnet/api/system.threading.threadabortexception) .NET Core 2.0 - `TimeSpan`