diff --git a/PolyShim.Tests/Net50/InterlockedTests.cs b/PolyShim.Tests/Net50/InterlockedTests.cs index ef01b3e8..350b73af 100644 --- a/PolyShim.Tests/Net50/InterlockedTests.cs +++ b/PolyShim.Tests/Net50/InterlockedTests.cs @@ -42,17 +42,17 @@ public void Or_Test() i.Should().Be(unchecked((int)0xFFFFFFFF)); // uint - uint ui = 0x0000FFFF; + var ui = (uint)0x0000FFFF; Interlocked.Or(ref ui, 0xFFFF0000).Should().Be(0x0000FFFF); ui.Should().Be(0xFFFFFFFF); // long - long l = 0x00000000FFFFFFFF; + var l = (long)0x00000000FFFFFFFF; Interlocked.Or(ref l, unchecked((long)0xFFFFFFFF00000000)).Should().Be(0x00000000FFFFFFFF); l.Should().Be(unchecked((long)0xFFFFFFFFFFFFFFFF)); // ulong - ulong ul = 0x00000000FFFFFFFF; + var ul = (ulong)0x00000000FFFFFFFF; Interlocked.Or(ref ul, 0xFFFFFFFF00000000).Should().Be(0x00000000FFFFFFFF); ul.Should().Be(0xFFFFFFFFFFFFFFFF); } diff --git a/PolyShim.Tests/Net80/RandomTests.cs b/PolyShim.Tests/Net80/RandomTests.cs index 33c2412a..44aa50e0 100644 --- a/PolyShim.Tests/Net80/RandomTests.cs +++ b/PolyShim.Tests/Net80/RandomTests.cs @@ -33,7 +33,7 @@ public void GetItems_Span_Test() { // Arrange var random = new Random(0); - ReadOnlySpan choices = [1, 2, 3, 4, 5]; + var choices = (ReadOnlySpan)[1, 2, 3, 4, 5]; for (var i = 0; i < 100; i++) { @@ -55,8 +55,8 @@ public void GetItems_SpanDestination_Test() { // Arrange var random = new Random(0); - ReadOnlySpan choices = [1, 2, 3, 4, 5]; - Span destination = new int[3]; + var choices = (ReadOnlySpan)[1, 2, 3, 4, 5]; + var destination = (Span)new int[3]; for (var i = 0; i < 100; i++) { diff --git a/PolyShim.Tests/Net90/FileTests.cs b/PolyShim.Tests/Net90/FileTests.cs index f603d24f..72f48014 100644 --- a/PolyShim.Tests/Net90/FileTests.cs +++ b/PolyShim.Tests/Net90/FileTests.cs @@ -43,7 +43,7 @@ public void AppendAllBytes_Span_Test() File.WriteAllBytes(tempFilePath, [0x00, 0x01, 0x02]); // Act - ReadOnlySpan bytes = [0x0A, 0x0B, 0x0C]; + var bytes = (ReadOnlySpan)[0x0A, 0x0B, 0x0C]; File.AppendAllBytes(tempFilePath, bytes); // Assert @@ -90,7 +90,7 @@ public async Task AppendAllBytesAsync_Memory_Test() await File.WriteAllBytesAsync(tempFilePath, [0x00, 0x01, 0x02]); // Act - ReadOnlyMemory bytes = new byte[] { 0x0A, 0x0B, 0x0C }; + var bytes = (ReadOnlyMemory)new byte[] { 0x0A, 0x0B, 0x0C }; await File.AppendAllBytesAsync(tempFilePath, bytes); // Assert diff --git a/PolyShim.Tests/NetCore21/MemoryExtensionsTests.cs b/PolyShim.Tests/NetCore21/MemoryExtensionsTests.cs index df7f2b27..9c92d0bb 100644 --- a/PolyShim.Tests/NetCore21/MemoryExtensionsTests.cs +++ b/PolyShim.Tests/NetCore21/MemoryExtensionsTests.cs @@ -90,7 +90,7 @@ public void Array_CopyTo_Span_Test() { // Arrange var array = new[] { 1, 2, 3 }; - Span destination = new int[3]; + var destination = (Span)new int[3]; // Act array.CopyTo(destination); @@ -104,7 +104,7 @@ public void Array_CopyTo_Memory_Test() { // Arrange var array = new[] { 1, 2, 3 }; - Memory destination = new int[3]; + var destination = (Memory)new int[3]; // Act array.CopyTo(destination); @@ -190,7 +190,7 @@ public void String_AsMemory_Start_Length_Test() public void Span_IndexOf_Found_Test() { // Arrange - Span span = [10, 20, 30, 40, 50]; + var span = (Span)[10, 20, 30, 40, 50]; // Act & Assert span.IndexOf(30).Should().Be(2); @@ -200,7 +200,7 @@ public void Span_IndexOf_Found_Test() public void Span_IndexOf_NotFound_Test() { // Arrange - Span span = [10, 20, 30]; + var span = (Span)[10, 20, 30]; // Act & Assert span.IndexOf(99).Should().Be(-1); @@ -210,8 +210,8 @@ public void Span_IndexOf_NotFound_Test() public void Span_SequenceEqual_Equal_Test() { // Arrange - Span span = [1, 2, 3]; - ReadOnlySpan other = [1, 2, 3]; + var span = (Span)[1, 2, 3]; + var other = (ReadOnlySpan)[1, 2, 3]; // Act & Assert span.SequenceEqual(other).Should().BeTrue(); @@ -221,8 +221,8 @@ public void Span_SequenceEqual_Equal_Test() public void Span_SequenceEqual_NotEqual_Test() { // Arrange - Span span = [1, 2, 3]; - ReadOnlySpan other = [1, 2, 4]; + var span = (Span)[1, 2, 3]; + var other = (ReadOnlySpan)[1, 2, 4]; // Act & Assert span.SequenceEqual(other).Should().BeFalse(); @@ -232,8 +232,8 @@ public void Span_SequenceEqual_NotEqual_Test() public void Span_SequenceEqual_DifferentLengths_Test() { // Arrange - Span span = [1, 2, 3]; - ReadOnlySpan other = [1, 2]; + var span = (Span)[1, 2, 3]; + var other = (ReadOnlySpan)[1, 2]; // Act & Assert span.SequenceEqual(other).Should().BeFalse(); @@ -243,7 +243,7 @@ public void Span_SequenceEqual_DifferentLengths_Test() public void Span_Reverse_Test() { // Arrange - Span span = [1, 2, 3, 4, 5]; + var span = (Span)[1, 2, 3, 4, 5]; // Act span.Reverse(); @@ -256,7 +256,7 @@ public void Span_Reverse_Test() public void ReadOnlySpan_IndexOf_Found_Test() { // Arrange - ReadOnlySpan span = [10, 20, 30, 40, 50]; + var span = (ReadOnlySpan)[10, 20, 30, 40, 50]; // Act & Assert span.IndexOf(30).Should().Be(2); @@ -266,7 +266,7 @@ public void ReadOnlySpan_IndexOf_Found_Test() public void ReadOnlySpan_IndexOf_NotFound_Test() { // Arrange - ReadOnlySpan span = [10, 20, 30]; + var span = (ReadOnlySpan)[10, 20, 30]; // Act & Assert span.IndexOf(99).Should().Be(-1); @@ -276,8 +276,8 @@ public void ReadOnlySpan_IndexOf_NotFound_Test() public void ReadOnlySpan_SequenceEqual_Equal_Test() { // Arrange - ReadOnlySpan span = [1, 2, 3]; - ReadOnlySpan other = [1, 2, 3]; + var span = (ReadOnlySpan)[1, 2, 3]; + var other = (ReadOnlySpan)[1, 2, 3]; // Act & Assert span.SequenceEqual(other).Should().BeTrue(); @@ -287,8 +287,8 @@ public void ReadOnlySpan_SequenceEqual_Equal_Test() public void ReadOnlySpan_SequenceEqual_NotEqual_Test() { // Arrange - ReadOnlySpan span = [1, 2, 3]; - ReadOnlySpan other = [1, 9, 3]; + var span = (ReadOnlySpan)[1, 2, 3]; + var other = (ReadOnlySpan)[1, 9, 3]; // Act & Assert span.SequenceEqual(other).Should().BeFalse(); diff --git a/PolyShim.Tests/NetCore21/MemoryTests.cs b/PolyShim.Tests/NetCore21/MemoryTests.cs index 9d524ccb..4143ebbe 100644 --- a/PolyShim.Tests/NetCore21/MemoryTests.cs +++ b/PolyShim.Tests/NetCore21/MemoryTests.cs @@ -10,7 +10,7 @@ public class MemoryTests public void ImplicitConversion_Test() { // Act - Memory memory = new byte[] { 1, 2, 3, 4, 5 }; + var memory = (Memory)new byte[] { 1, 2, 3, 4, 5 }; // Assert memory.ToArray().Should().Equal(1, 2, 3, 4, 5); @@ -20,7 +20,7 @@ public void ImplicitConversion_Test() public void Slice_Test() { // Arrange - Memory memory = new byte[] { 10, 20, 30, 40, 50 }; + var memory = (Memory)new byte[] { 10, 20, 30, 40, 50 }; // Act & Assert memory.Slice(0, 2).ToArray().Should().Equal(10, 20); @@ -32,8 +32,8 @@ public void Slice_Test() public void CopyTo_Test() { // Arrange - Memory source = new byte[] { 1, 2, 3, 4, 5 }; - Memory destination = new byte[5]; + var source = (Memory)new byte[] { 1, 2, 3, 4, 5 }; + var destination = (Memory)new byte[5]; // Act source.CopyTo(destination); @@ -46,8 +46,8 @@ public void CopyTo_Test() public void TryCopyTo_Test() { // Arrange - Memory source = new byte[] { 1, 2, 3, 4, 5 }; - Memory destination = new byte[5]; + var source = (Memory)new byte[] { 1, 2, 3, 4, 5 }; + var destination = (Memory)new byte[5]; // Act var result = source.TryCopyTo(destination); @@ -62,9 +62,9 @@ public void Equals_Test() { // Arrange var arr = new byte[] { 1, 2, 3 }; - Memory a = arr; - Memory b = arr; - Memory c = new byte[] { 1, 2, 3 }; + var a = (Memory)arr; + var b = (Memory)arr; + var c = (Memory)new byte[] { 1, 2, 3 }; // Act & Assert a.Equals(b).Should().BeTrue(); @@ -79,9 +79,9 @@ public void GetHashCode_Test() { // Arrange var arr = new byte[] { 1, 2, 3 }; - Memory a = arr; - Memory b = arr; - Memory c = new byte[] { 1, 2, 3 }; + var a = (Memory)arr; + var b = (Memory)arr; + var c = (Memory)new byte[] { 1, 2, 3 }; // Act & Assert a.GetHashCode().Should().Be(b.GetHashCode()); diff --git a/PolyShim.Tests/NetCore21/ReadOnlyMemoryTests.cs b/PolyShim.Tests/NetCore21/ReadOnlyMemoryTests.cs index 8d0d1180..b5beeba2 100644 --- a/PolyShim.Tests/NetCore21/ReadOnlyMemoryTests.cs +++ b/PolyShim.Tests/NetCore21/ReadOnlyMemoryTests.cs @@ -10,7 +10,7 @@ public class ReadOnlyMemoryTests public void ImplicitConversion_Test() { // Act - ReadOnlyMemory memory = new byte[] { 1, 2, 3, 4, 5 }; + var memory = (ReadOnlyMemory)new byte[] { 1, 2, 3, 4, 5 }; // Assert memory.ToArray().Should().Equal(1, 2, 3, 4, 5); @@ -20,7 +20,7 @@ public void ImplicitConversion_Test() public void Slice_Test() { // Arrange - ReadOnlyMemory memory = new byte[] { 10, 20, 30, 40, 50 }; + var memory = (ReadOnlyMemory)new byte[] { 10, 20, 30, 40, 50 }; // Act & Assert memory.Slice(0, 2).ToArray().Should().Equal(10, 20); @@ -32,8 +32,8 @@ public void Slice_Test() public void CopyTo_Test() { // Arrange - ReadOnlyMemory source = new byte[] { 1, 2, 3, 4, 5 }; - Memory destination = new byte[5]; + var source = (ReadOnlyMemory)new byte[] { 1, 2, 3, 4, 5 }; + var destination = (Memory)new byte[5]; // Act source.CopyTo(destination); @@ -46,8 +46,8 @@ public void CopyTo_Test() public void TryCopyTo_Test() { // Arrange - ReadOnlyMemory source = new byte[] { 1, 2, 3, 4, 5 }; - Memory destination = new byte[5]; + var source = (ReadOnlyMemory)new byte[] { 1, 2, 3, 4, 5 }; + var destination = (Memory)new byte[5]; // Act var result = source.TryCopyTo(destination); @@ -62,9 +62,9 @@ public void Equals_Test() { // Arrange var arr = new byte[] { 1, 2, 3 }; - ReadOnlyMemory a = arr; - ReadOnlyMemory b = arr; - ReadOnlyMemory c = new byte[] { 1, 2, 3 }; + var a = (ReadOnlyMemory)arr; + var b = (ReadOnlyMemory)arr; + var c = (ReadOnlyMemory)new byte[] { 1, 2, 3 }; // Act & Assert a.Equals(b).Should().BeTrue(); @@ -79,9 +79,9 @@ public void GetHashCode_Test() { // Arrange var arr = new byte[] { 1, 2, 3 }; - ReadOnlyMemory a = arr; - ReadOnlyMemory b = arr; - ReadOnlyMemory c = new byte[] { 1, 2, 3 }; + var a = (ReadOnlyMemory)arr; + var b = (ReadOnlyMemory)arr; + var c = (ReadOnlyMemory)new byte[] { 1, 2, 3 }; // Act & Assert a.GetHashCode().Should().Be(b.GetHashCode()); diff --git a/PolyShim.Tests/NetCore21/ReadOnlySpanTests.cs b/PolyShim.Tests/NetCore21/ReadOnlySpanTests.cs index 2768bffe..3c639e9f 100644 --- a/PolyShim.Tests/NetCore21/ReadOnlySpanTests.cs +++ b/PolyShim.Tests/NetCore21/ReadOnlySpanTests.cs @@ -11,7 +11,7 @@ public class ReadOnlySpanTests public void ImplicitConversion_Test() { // Act - ReadOnlySpan readOnlySpan = [1, 2, 3, 4, 5]; + var readOnlySpan = (ReadOnlySpan)[1, 2, 3, 4, 5]; // Assert readOnlySpan.ToArray().Should().Equal(1, 2, 3, 4, 5); @@ -21,7 +21,7 @@ public void ImplicitConversion_Test() public void Indexer_Test() { // Arrange - ReadOnlySpan readOnlySpan = [10, 20, 30, 40, 50]; + var readOnlySpan = (ReadOnlySpan)[10, 20, 30, 40, 50]; // Act & Assert readOnlySpan[0].Should().Be(10); @@ -35,7 +35,7 @@ public void Indexer_Test() public void Slice_Test() { // Arrange - ReadOnlySpan readOnlySpan = [10, 20, 30, 40, 50]; + var readOnlySpan = (ReadOnlySpan)[10, 20, 30, 40, 50]; // Act var slice = readOnlySpan.Slice(1, 3); @@ -48,8 +48,8 @@ public void Slice_Test() public void CopyTo_Test() { // Arrange - ReadOnlySpan source = [1, 2, 3, 4, 5]; - Span destination = new byte[5]; + var source = (ReadOnlySpan)[1, 2, 3, 4, 5]; + var destination = (Span)new byte[5]; // Act source.CopyTo(destination); @@ -62,8 +62,8 @@ public void CopyTo_Test() public void TryCopyTo_Test() { // Arrange - ReadOnlySpan source = [1, 2, 3, 4, 5]; - Span destination = new byte[5]; + var source = (ReadOnlySpan)[1, 2, 3, 4, 5]; + var destination = (Span)new byte[5]; // Act var result = source.TryCopyTo(destination); @@ -77,7 +77,7 @@ public void TryCopyTo_Test() public void Enumeration_Test() { // Arrange - ReadOnlySpan readOnlySpan = [1, 2, 3, 4, 5]; + var readOnlySpan = (ReadOnlySpan)[1, 2, 3, 4, 5]; var result = new List(); // Act @@ -92,11 +92,11 @@ public void Enumeration_Test() public void Contains_Test() { // Act & Assert - ReadOnlySpan span = [1, 2, 3, 4, 5]; + var span = (ReadOnlySpan)[1, 2, 3, 4, 5]; span.Contains((byte)3).Should().BeTrue(); span.Contains((byte)10).Should().BeFalse(); - ReadOnlySpan emptySpan = []; + var emptySpan = (ReadOnlySpan)[]; emptySpan.Contains((byte)1).Should().BeFalse(); } } diff --git a/PolyShim.Tests/NetCore21/SpanTests.cs b/PolyShim.Tests/NetCore21/SpanTests.cs index bd3c5435..6a186316 100644 --- a/PolyShim.Tests/NetCore21/SpanTests.cs +++ b/PolyShim.Tests/NetCore21/SpanTests.cs @@ -11,7 +11,7 @@ public class SpanTests public void ImplicitConversion_Test() { // Act - Span span = [1, 2, 3, 4, 5]; + var span = (Span)[1, 2, 3, 4, 5]; // Assert span.ToArray().Should().Equal(1, 2, 3, 4, 5); @@ -21,7 +21,7 @@ public void ImplicitConversion_Test() public void Indexer_Test() { // Arrange - Span span = [10, 20, 30, 40, 50]; + var span = (Span)[10, 20, 30, 40, 50]; // Act & Assert span[0].Should().Be(10); @@ -35,7 +35,7 @@ public void Indexer_Test() public void Slice_Test() { // Arrange - Span span = [1, 2, 3, 4, 5]; + var span = (Span)[1, 2, 3, 4, 5]; // Act var slice = span.Slice(1, 3); @@ -48,7 +48,7 @@ public void Slice_Test() public void Fill_Test() { // Arrange - Span span = [1, 2, 3, 4, 5]; + var span = (Span)[1, 2, 3, 4, 5]; // Act span.Fill(42); @@ -61,7 +61,7 @@ public void Fill_Test() public void Clear_Test() { // Arrange - Span span = [1, 2, 3, 4, 5]; + var span = (Span)[1, 2, 3, 4, 5]; // Act span.Clear(); @@ -74,8 +74,8 @@ public void Clear_Test() public void CopyTo_Test() { // Arrange - Span source = [1, 2, 3, 4, 5]; - Span destination = stackalloc byte[5]; + var source = (Span)[1, 2, 3, 4, 5]; + var destination = (Span)stackalloc byte[5]; // Act source.CopyTo(destination); @@ -88,8 +88,8 @@ public void CopyTo_Test() public void TryCopyTo_Test() { // Arrange - Span source = [1, 2, 3, 4, 5]; - Span destination = stackalloc byte[5]; + var source = (Span)[1, 2, 3, 4, 5]; + var destination = (Span)stackalloc byte[5]; // Act var result = source.TryCopyTo(destination); @@ -103,7 +103,7 @@ public void TryCopyTo_Test() public void Enumeration_Test() { // Arrange - Span span = [1, 2, 3, 4, 5]; + var span = (Span)[1, 2, 3, 4, 5]; var collected = new List(); // Act @@ -118,11 +118,11 @@ public void Enumeration_Test() public void Contains_Test() { // Act & Assert - Span span = [1, 2, 3, 4, 5]; + var span = (Span)[1, 2, 3, 4, 5]; span.Contains((byte)3).Should().BeTrue(); span.Contains((byte)10).Should().BeFalse(); - Span emptySpan = []; + var emptySpan = (Span)[]; emptySpan.Contains((byte)1).Should().BeFalse(); } } diff --git a/PolyShim/Net50/HttpClient.cs b/PolyShim/Net50/HttpClient.cs index 022992d9..0c1b6a9c 100644 --- a/PolyShim/Net50/HttpClient.cs +++ b/PolyShim/Net50/HttpClient.cs @@ -1,5 +1,6 @@ -#if FEATURE_HTTPCLIENT #if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// HttpClient is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_HTTPCLIENT #nullable enable #pragma warning disable CS0436 @@ -15,6 +16,7 @@ #endif internal static class MemberPolyfills_Net50_HttpClient { + // Task infrastructure is required for async method support #if FEATURE_TASK extension(HttpClient httpClient) { diff --git a/PolyShim/Net50/HttpContent.cs b/PolyShim/Net50/HttpContent.cs index 1b07b579..56c2d6e4 100644 --- a/PolyShim/Net50/HttpContent.cs +++ b/PolyShim/Net50/HttpContent.cs @@ -1,5 +1,6 @@ -#if FEATURE_HTTPCLIENT #if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// HttpClient is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_HTTPCLIENT #nullable enable #pragma warning disable CS0436 @@ -14,6 +15,7 @@ #endif internal static class MemberPolyfills_Net50_HttpContent { + // Task infrastructure is required for async method support #if FEATURE_TASK extension(HttpContent httpContent) { diff --git a/PolyShim/Net50/IntPtr.cs b/PolyShim/Net50/IntPtr.cs index a1be27a1..3db565f2 100644 --- a/PolyShim/Net50/IntPtr.cs +++ b/PolyShim/Net50/IntPtr.cs @@ -35,13 +35,13 @@ public static bool TryParse(string? s, out IntPtr result) if (IntPtr.Size == 4) { var success = int.TryParse(s, out var intResult); - result = new IntPtr(intResult); + result = new(intResult); return success; } else { var success = long.TryParse(s, out var longResult); - result = new IntPtr(longResult); + result = new(longResult); return success; } } diff --git a/PolyShim/Net50/Interlocked.cs b/PolyShim/Net50/Interlocked.cs index e4b47165..b0e53ad8 100644 --- a/PolyShim/Net50/Interlocked.cs +++ b/PolyShim/Net50/Interlocked.cs @@ -15,8 +15,8 @@ internal static class MemberPolyfills_Net50_Interlocked // https://learn.microsoft.com/dotnet/api/system.threading.interlocked.and#system-threading-interlocked-and(system-int32@-system-int32) public static int And(ref int location1, int value) { - int current; - int original; + var current = 0; + var original = 0; do { current = location1; @@ -27,6 +27,7 @@ public static int And(ref int location1, int value) return original; } + // Unsafe code is required for operating on unsigned integer references #if ALLOW_UNSAFE_BLOCKS // https://learn.microsoft.com/dotnet/api/system.threading.interlocked.and#system-threading-interlocked-and(system-uint32@-system-uint32) public static uint And(ref uint location1, uint value) @@ -45,8 +46,8 @@ public static uint And(ref uint location1, uint value) // https://learn.microsoft.com/dotnet/api/system.threading.interlocked.and#system-threading-interlocked-and(system-int64@-system-int64) public static long And(ref long location1, long value) { - long current; - long original; + var current = 0L; + var original = 0L; do { current = location1; @@ -57,6 +58,7 @@ public static long And(ref long location1, long value) return original; } + // Unsafe code is required for operating on unsigned integer references #if ALLOW_UNSAFE_BLOCKS // https://learn.microsoft.com/dotnet/api/system.threading.interlocked.and#system-threading-interlocked-and(system-uint64@-system-uint64) public static ulong And(ref ulong location1, ulong value) @@ -75,8 +77,8 @@ public static ulong And(ref ulong location1, ulong value) // https://learn.microsoft.com/dotnet/api/system.threading.interlocked.or#system-threading-interlocked-or(system-int32@-system-int32) public static int Or(ref int location1, int value) { - int current; - int original; + var current = 0; + var original = 0; do { current = location1; @@ -87,6 +89,7 @@ public static int Or(ref int location1, int value) return original; } + // Unsafe code is required for operating on unsigned integer references #if ALLOW_UNSAFE_BLOCKS // https://learn.microsoft.com/dotnet/api/system.threading.interlocked.or#system-threading-interlocked-or(system-uint32@-system-uint32) public static uint Or(ref uint location1, uint value) @@ -105,8 +108,8 @@ public static uint Or(ref uint location1, uint value) // https://learn.microsoft.com/dotnet/api/system.threading.interlocked.or#system-threading-interlocked-or(system-int64@-system-int64) public static long Or(ref long location1, long value) { - long current; - long original; + var current = 0L; + var original = 0L; do { current = location1; @@ -117,6 +120,7 @@ public static long Or(ref long location1, long value) return original; } + // Unsafe code is required for operating on unsigned integer references #if ALLOW_UNSAFE_BLOCKS // https://learn.microsoft.com/dotnet/api/system.threading.interlocked.or#system-threading-interlocked-or(system-uint64@-system-uint64) public static ulong Or(ref ulong location1, ulong value) diff --git a/PolyShim/Net50/Process.cs b/PolyShim/Net50/Process.cs index 711ceed7..e9c23ecf 100644 --- a/PolyShim/Net50/Process.cs +++ b/PolyShim/Net50/Process.cs @@ -1,5 +1,6 @@ -#if FEATURE_PROCESS #if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// Process is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_PROCESS #nullable enable #pragma warning disable CS0436 @@ -14,6 +15,7 @@ #endif internal static class MemberPolyfills_Net50_Process { + // Task infrastructure is required for async method support #if FEATURE_TASK extension(Process process) { diff --git a/PolyShim/Net50/TaskCompletionSource.cs b/PolyShim/Net50/TaskCompletionSource.cs index 71cc5416..a46f28ff 100644 --- a/PolyShim/Net50/TaskCompletionSource.cs +++ b/PolyShim/Net50/TaskCompletionSource.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/Net50/TaskCompletionSourceOfT.cs b/PolyShim/Net50/TaskCompletionSourceOfT.cs index 28e65f2b..7d43854f 100644 --- a/PolyShim/Net50/TaskCompletionSourceOfT.cs +++ b/PolyShim/Net50/TaskCompletionSourceOfT.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/Net50/UIntPtr.cs b/PolyShim/Net50/UIntPtr.cs index 221df789..553bb71a 100644 --- a/PolyShim/Net50/UIntPtr.cs +++ b/PolyShim/Net50/UIntPtr.cs @@ -37,13 +37,13 @@ public static bool TryParse(string? s, out UIntPtr result) if (UIntPtr.Size == 4) { var success = uint.TryParse(s, out var intResult); - result = new UIntPtr(intResult); + result = new(intResult); return success; } else { var success = ulong.TryParse(s, out var longResult); - result = new UIntPtr(longResult); + result = new(longResult); return success; } } diff --git a/PolyShim/Net60/Parallel.cs b/PolyShim/Net60/Parallel.cs index 5085983d..f6bc0d6d 100644 --- a/PolyShim/Net60/Parallel.cs +++ b/PolyShim/Net60/Parallel.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETCOREAPP && !NET6_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/Net60/Random.cs b/PolyShim/Net60/Random.cs index c3d433b1..9bf25eed 100644 --- a/PolyShim/Net60/Random.cs +++ b/PolyShim/Net60/Random.cs @@ -35,7 +35,7 @@ public long NextInt64(long minValue, long maxValue) var buffer = ArrayPool.Shared.Rent(8); try { - ulong ulongRand; + var ulongRand = 0UL; do { random.NextBytes(buffer.AsSpan(0, 8)); @@ -73,7 +73,7 @@ public float NextSingle() } // https://learn.microsoft.com/dotnet/api/system.random.shared - public static Random Shared => RandomEx.Shared ??= new Random(); + public static Random Shared => RandomEx.Shared ??= new(); } } #endif diff --git a/PolyShim/Net60/Task.cs b/PolyShim/Net60/Task.cs index 0013e956..996d4faf 100644 --- a/PolyShim/Net60/Task.cs +++ b/PolyShim/Net60/Task.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETCOREAPP && !NET6_0_OR_GREATER) || (NET45_OR_GREATER) || (NETSTANDARD) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/Net70/File.cs b/PolyShim/Net70/File.cs index d7ba04c8..257010f5 100644 --- a/PolyShim/Net70/File.cs +++ b/PolyShim/Net70/File.cs @@ -105,6 +105,7 @@ public static void SetUnixFileMode(string path, UnixFileMode mode) } } + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.file.readlinesasync#system-io-file-readlinesasync(system-string-system-text-encoding-system-threading-cancellationtoken) public static async IAsyncEnumerable ReadLinesAsync( diff --git a/PolyShim/Net70/IntPtr.cs b/PolyShim/Net70/IntPtr.cs index fb7858ff..c0f26a5b 100644 --- a/PolyShim/Net70/IntPtr.cs +++ b/PolyShim/Net70/IntPtr.cs @@ -19,13 +19,13 @@ public static bool TryParse(string? s, IFormatProvider? provider, out IntPtr res if (IntPtr.Size == 4) { var success = int.TryParse(s, provider, out var intResult); - result = new IntPtr(intResult); + result = new(intResult); return success; } else { var success = long.TryParse(s, provider, out var longResult); - result = new IntPtr(longResult); + result = new(longResult); return success; } } diff --git a/PolyShim/Net70/Stopwatch.cs b/PolyShim/Net70/Stopwatch.cs index 792f37c9..48551000 100644 --- a/PolyShim/Net70/Stopwatch.cs +++ b/PolyShim/Net70/Stopwatch.cs @@ -21,17 +21,17 @@ public static TimeSpan GetElapsedTime(long startingTimestamp, long endingTimesta if (tickFrequency == TimeSpan.TicksPerSecond) { - return new TimeSpan(ticks); + return new(ticks); } else if (tickFrequency > TimeSpan.TicksPerSecond) { var ticksPerStopwatchTick = (double)tickFrequency / TimeSpan.TicksPerSecond; - return new TimeSpan((long)(ticks / ticksPerStopwatchTick)); + return new((long)(ticks / ticksPerStopwatchTick)); } else { var ticksPerStopwatchTick = (double)TimeSpan.TicksPerSecond / tickFrequency; - return new TimeSpan((long)(ticks * ticksPerStopwatchTick)); + return new((long)(ticks * ticksPerStopwatchTick)); } } diff --git a/PolyShim/Net70/Stream.cs b/PolyShim/Net70/Stream.cs index 0e34ebc0..cbb9a7df 100644 --- a/PolyShim/Net70/Stream.cs +++ b/PolyShim/Net70/Stream.cs @@ -34,6 +34,7 @@ public void ReadExactly(byte[] buffer, int offset, int count) } } + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.stream.readexactlyasync#system-io-stream-readexactlyasync(system-byte()-system-int32-system-int32-system-threading-cancellationtoken) public async Task ReadExactlyAsync( @@ -90,6 +91,7 @@ public void ReadExactly(Span buffer) bufferArray.CopyTo(buffer); } + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.stream.readatleastasync public async Task ReadAtLeastAsync( diff --git a/PolyShim/Net70/TextReader.cs b/PolyShim/Net70/TextReader.cs index 6f35f00f..6279da99 100644 --- a/PolyShim/Net70/TextReader.cs +++ b/PolyShim/Net70/TextReader.cs @@ -17,6 +17,7 @@ internal static class MemberPolyfills_Net70_TextReader { extension(TextReader reader) { + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.textreader.readlineasync#system-io-textreader-readlineasync(system-threading-cancellationtoken) public Task ReadLineAsync(CancellationToken cancellationToken) diff --git a/PolyShim/Net70/UIntPtr.cs b/PolyShim/Net70/UIntPtr.cs index 4dd51d48..bc2d49a6 100644 --- a/PolyShim/Net70/UIntPtr.cs +++ b/PolyShim/Net70/UIntPtr.cs @@ -18,13 +18,13 @@ public static bool TryParse(string? s, IFormatProvider? provider, out UIntPtr re if (IntPtr.Size == 4) { var success = uint.TryParse(s, provider, out var intResult); - result = new UIntPtr(intResult); + result = new(intResult); return success; } else { var success = ulong.TryParse(s, provider, out var longResult); - result = new UIntPtr(longResult); + result = new(longResult); return success; } } diff --git a/PolyShim/Net80/CancellationTokenSource.cs b/PolyShim/Net80/CancellationTokenSource.cs index 4b1cd1c1..0f40cabb 100644 --- a/PolyShim/Net80/CancellationTokenSource.cs +++ b/PolyShim/Net80/CancellationTokenSource.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETCOREAPP && !NET8_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/Net80/ITimer.cs b/PolyShim/Net80/ITimer.cs index a12fe3a2..b09358e1 100644 --- a/PolyShim/Net80/ITimer.cs +++ b/PolyShim/Net80/ITimer.cs @@ -9,7 +9,8 @@ namespace System.Threading; // https://learn.microsoft.com/dotnet/api/system.threading.itimer internal interface ITimer : IDisposable -#if FEATURE_ASYNCINTERFACES + // Task infrastructure is required for async method support +#if FEATURE_TASK , IAsyncDisposable #endif { diff --git a/PolyShim/Net80/Parallel.cs b/PolyShim/Net80/Parallel.cs index 5d047e70..0750daa9 100644 --- a/PolyShim/Net80/Parallel.cs +++ b/PolyShim/Net80/Parallel.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETCOREAPP && !NET8_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/Net80/TextWriter.cs b/PolyShim/Net80/TextWriter.cs index 095dd161..b26fb23f 100644 --- a/PolyShim/Net80/TextWriter.cs +++ b/PolyShim/Net80/TextWriter.cs @@ -14,6 +14,7 @@ internal static class MemberPolyfills_Net80_TextWriter { extension(TextWriter writer) { + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.textwriter.flushasync#system-io-textwriter-flushasync(system-threading-cancellationtoken) public Task FlushAsync(CancellationToken cancellationToken) diff --git a/PolyShim/Net80/TimeProvider.cs b/PolyShim/Net80/TimeProvider.cs index cfa354c2..d73fd361 100644 --- a/PolyShim/Net80/TimeProvider.cs +++ b/PolyShim/Net80/TimeProvider.cs @@ -28,7 +28,7 @@ public DateTimeOffset GetLocalNow() { var utcDateTime = GetUtcNow(); var offset = LocalTimeZone.GetUtcOffset(utcDateTime); - return new DateTimeOffset(utcDateTime.DateTime + offset, offset); + return new(utcDateTime.DateTime + offset, offset); } public virtual long GetTimestamp() => Stopwatch.GetTimestamp(); @@ -62,7 +62,7 @@ public SystemTimeProviderTimer( object? state ) { - _timer = new Timer(callback, state, dueTime, period); + _timer = new(callback, state, dueTime, period); } public bool Change(TimeSpan dueTime, TimeSpan period) @@ -82,7 +82,8 @@ public void Dispose() _timer.Dispose(); } -#if FEATURE_ASYNCINTERFACES + // Task infrastructure is required for async method support +#if FEATURE_TASK public ValueTask DisposeAsync() => _timer.DisposeAsync(); #endif } diff --git a/PolyShim/Net90/File.cs b/PolyShim/Net90/File.cs index b94d8fc6..cf1c8df9 100644 --- a/PolyShim/Net90/File.cs +++ b/PolyShim/Net90/File.cs @@ -34,6 +34,7 @@ public static void AppendAllBytes(string path, byte[] bytes) public static void AppendAllBytes(string path, ReadOnlySpan bytes) => File.AppendAllBytes(path, bytes.ToArray()); + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.file.appendallbytesasync#system-io-file-appendallbytesasync(system-string-system-byte()-system-threading-cancellationtoken) public static async Task AppendAllBytesAsync( diff --git a/PolyShim/Net90/Lock.cs b/PolyShim/Net90/Lock.cs index e6b48b26..1667e065 100644 --- a/PolyShim/Net90/Lock.cs +++ b/PolyShim/Net90/Lock.cs @@ -33,13 +33,13 @@ public Scope EnterScope() #if NETFRAMEWORK && !NET40_OR_GREATER // Older versions of the framework don't have the overload of Monitor.Enter(...) that accepts a ref bool Monitor.Enter(this); - return new Scope(this); + return new(this); #else var acquiredLock = false; try { Monitor.Enter(this, ref acquiredLock); - return new Scope(this); + return new(this); } // Ensure that the lock is released if the owning thread is aborted. // Implementation reference: diff --git a/PolyShim/Net90/Task.cs b/PolyShim/Net90/Task.cs index 085faeb1..0b8436e0 100644 --- a/PolyShim/Net90/Task.cs +++ b/PolyShim/Net90/Task.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETCOREAPP && !NET9_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore10/AggregateException.cs b/PolyShim/NetCore10/AggregateException.cs index 4220fc23..4d02f6e1 100644 --- a/PolyShim/NetCore10/AggregateException.cs +++ b/PolyShim/NetCore10/AggregateException.cs @@ -62,7 +62,7 @@ public AggregateException Flatten() } } - return new AggregateException(innerExceptions); + return new(innerExceptions); } public void Handle(Func predicate) diff --git a/PolyShim/NetCore10/ParallelOptions.cs b/PolyShim/NetCore10/ParallelOptions.cs index bf4ebb24..fc68a1e7 100644 --- a/PolyShim/NetCore10/ParallelOptions.cs +++ b/PolyShim/NetCore10/ParallelOptions.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETFRAMEWORK && !NET40_OR_GREATER) || (NETSTANDARD && !NETSTANDARD2_0_OR_GREATER) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore10/SemaphoreSlim.cs b/PolyShim/NetCore10/SemaphoreSlim.cs index a38aae65..4bc94efa 100644 --- a/PolyShim/NetCore10/SemaphoreSlim.cs +++ b/PolyShim/NetCore10/SemaphoreSlim.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if NETFRAMEWORK && !NET45_OR_GREATER +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore10/Task.cs b/PolyShim/NetCore10/Task.cs index 1fe69680..78ed46c3 100644 --- a/PolyShim/NetCore10/Task.cs +++ b/PolyShim/NetCore10/Task.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETFRAMEWORK && !NET46_OR_GREATER) || (NETSTANDARD && !NETSTANDARD1_3_OR_GREATER) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 @@ -176,8 +177,8 @@ public static Task Delay(TimeSpan delay, CancellationToken cancellationToken) return tcs.Task; } - Timer? timer = null; - CancellationTokenRegistration registration = default; + var timer = (Timer?)null; + var registration = default(CancellationTokenRegistration); void CleanupAndSetResult() { @@ -193,12 +194,7 @@ void CleanupAndSetCanceled() tcs.TrySetCanceled(); } - timer = new Timer( - _ => CleanupAndSetResult(), - null, - delay, - TimeSpan.FromMilliseconds(-1) - ); + timer = new(_ => CleanupAndSetResult(), null, delay, TimeSpan.FromMilliseconds(-1)); registration = cancellationToken.Register(() => CleanupAndSetCanceled()); diff --git a/PolyShim/NetCore10/TaskCompletionSource.cs b/PolyShim/NetCore10/TaskCompletionSource.cs index 21921e50..09227067 100644 --- a/PolyShim/NetCore10/TaskCompletionSource.cs +++ b/PolyShim/NetCore10/TaskCompletionSource.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETFRAMEWORK && !NET46_OR_GREATER) || (NETSTANDARD && !NETSTANDARD1_3_OR_GREATER) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore10/Version.cs b/PolyShim/NetCore10/Version.cs index 8ba812d0..a90dd2e9 100644 --- a/PolyShim/NetCore10/Version.cs +++ b/PolyShim/NetCore10/Version.cs @@ -24,7 +24,7 @@ public static bool TryParse(string? input, out Version? result) try { - result = new Version(input); + result = new(input); return true; } catch diff --git a/PolyShim/NetCore20/File.cs b/PolyShim/NetCore20/File.cs index 2e9a9860..1bafd9a7 100644 --- a/PolyShim/NetCore20/File.cs +++ b/PolyShim/NetCore20/File.cs @@ -19,6 +19,7 @@ internal static class MemberPolyfills_NetCore20_File #if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER extension(File) { + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.file.appendalllinesasync#system-io-file-appendalllinesasync(system-string-system-collections-generic-ienumerable((system-string))-system-threading-cancellationtoken) public static async Task AppendAllLinesAsync(string path, IEnumerable contents, CancellationToken cancellationToken = default) @@ -140,7 +141,7 @@ public static async Task ReadAllTextAsync(string path, CancellationToken { cancellationToken.ThrowIfCancellationRequested(); - int charsRead; + var charsRead = 0; while ((charsRead = await reader.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0) { cancellationToken.ThrowIfCancellationRequested(); @@ -168,7 +169,7 @@ public static async Task ReadAllTextAsync(string path, Encoding encoding { cancellationToken.ThrowIfCancellationRequested(); - int charsRead; + var charsRead = 0; while ((charsRead = await reader.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/PolyShim/NetCore20/Task.cs b/PolyShim/NetCore20/Task.cs index b40fdb24..a156b975 100644 --- a/PolyShim/NetCore20/Task.cs +++ b/PolyShim/NetCore20/Task.cs @@ -1,5 +1,6 @@ -#if FEATURE_TASK #if (NETCOREAPP && !NETCOREAPP2_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER) +// Task is not available on all target frameworks within this TFM range without a NuGet package reference +#if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore21/AsyncValueTaskMethodBuilder.cs b/PolyShim/NetCore21/AsyncValueTaskMethodBuilder.cs index 38d6c01e..2bdfee27 100644 --- a/PolyShim/NetCore21/AsyncValueTaskMethodBuilder.cs +++ b/PolyShim/NetCore21/AsyncValueTaskMethodBuilder.cs @@ -1,4 +1,5 @@ #if FEATURE_TASK +// Can be provided natively or by a compatibility package #if !FEATURE_VALUETASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore21/ConfiguredValueTaskAwaitable.cs b/PolyShim/NetCore21/ConfiguredValueTaskAwaitable.cs index 5afc0ea8..032b50de 100644 --- a/PolyShim/NetCore21/ConfiguredValueTaskAwaitable.cs +++ b/PolyShim/NetCore21/ConfiguredValueTaskAwaitable.cs @@ -1,4 +1,5 @@ #if FEATURE_TASK +// Can be provided natively or by a compatibility package #if !FEATURE_VALUETASK #nullable enable #pragma warning disable CS0436 @@ -17,7 +18,7 @@ internal readonly struct ConfiguredValueTaskAwaitable( bool continueOnCapturedContext ) { - public Awaiter GetAwaiter() => new Awaiter(value, continueOnCapturedContext); + public Awaiter GetAwaiter() => new(value, continueOnCapturedContext); #if !POLYSHIM_INCLUDE_COVERAGE [ExcludeFromCodeCoverage] @@ -55,7 +56,7 @@ internal readonly struct ConfiguredValueTaskAwaitable( bool continueOnCapturedContext ) { - public Awaiter GetAwaiter() => new Awaiter(value, continueOnCapturedContext); + public Awaiter GetAwaiter() => new(value, continueOnCapturedContext); #if !POLYSHIM_INCLUDE_COVERAGE [ExcludeFromCodeCoverage] diff --git a/PolyShim/NetCore21/IValueTaskSource.cs b/PolyShim/NetCore21/IValueTaskSource.cs index dc9cba4c..d641d74c 100644 --- a/PolyShim/NetCore21/IValueTaskSource.cs +++ b/PolyShim/NetCore21/IValueTaskSource.cs @@ -1,4 +1,5 @@ #if FEATURE_TASK +// Can be provided natively or by a compatibility package #if !FEATURE_VALUETASK_SOURCES #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore21/Span.cs b/PolyShim/NetCore21/Span.cs index 5edab3b4..e20f8f48 100644 --- a/PolyShim/NetCore21/Span.cs +++ b/PolyShim/NetCore21/Span.cs @@ -36,6 +36,7 @@ public Span(T[]? array, int start, int length) public Span(T[]? array) : this(array, 0, array?.Length ?? 0) { } + // Unsafe code is required for the pointer-accepting constructor #if ALLOW_UNSAFE_BLOCKS public unsafe Span(void* pointer, int length) : this(new T[length]) diff --git a/PolyShim/NetCore21/Stream.cs b/PolyShim/NetCore21/Stream.cs index 935d2456..312f8ee2 100644 --- a/PolyShim/NetCore21/Stream.cs +++ b/PolyShim/NetCore21/Stream.cs @@ -15,6 +15,7 @@ internal static class MemberPolyfills_NetCore21_Stream { extension(Stream stream) { + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.stream.copytoasync#system-io-stream-copytoasync(system-io-stream-system-threading-cancellationtoken) public async Task CopyToAsync( @@ -40,6 +41,7 @@ public void Write(ReadOnlySpan buffer) stream.Write(bufferArray, 0, bufferArray.Length); } + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.stream.readasync#system-io-stream-readasync(system-memory((system-byte))-system-threading-cancellationtoken) public async ValueTask ReadAsync( diff --git a/PolyShim/NetCore21/TextReader.cs b/PolyShim/NetCore21/TextReader.cs index c4792009..d037bf5f 100644 --- a/PolyShim/NetCore21/TextReader.cs +++ b/PolyShim/NetCore21/TextReader.cs @@ -25,6 +25,7 @@ public int Read(Span buffer) return result; } + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.textreader.readasync#system-io-textreader-readasync(system-memory((system-char))-system-threading-cancellationtoken) public async ValueTask ReadAsync( diff --git a/PolyShim/NetCore21/TextWriter.cs b/PolyShim/NetCore21/TextWriter.cs index 5e2705b8..9c726e37 100644 --- a/PolyShim/NetCore21/TextWriter.cs +++ b/PolyShim/NetCore21/TextWriter.cs @@ -22,6 +22,7 @@ public void Write(ReadOnlySpan buffer) writer.Write(bufferArray, 0, bufferArray.Length); } + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.textwriter.writeasync#system-io-textwriter-writeasync(system-readonlymemory((system-char))-system-threading-cancellationtoken) public async ValueTask WriteAsync( diff --git a/PolyShim/NetCore21/ValueTask.cs b/PolyShim/NetCore21/ValueTask.cs index fd5df764..4f8838c6 100644 --- a/PolyShim/NetCore21/ValueTask.cs +++ b/PolyShim/NetCore21/ValueTask.cs @@ -1,4 +1,5 @@ #if FEATURE_TASK +// Can be provided natively or by a compatibility package #if !FEATURE_VALUETASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore21/ValueTaskAwaiter.cs b/PolyShim/NetCore21/ValueTaskAwaiter.cs index 797fe691..b7778ebe 100644 --- a/PolyShim/NetCore21/ValueTaskAwaiter.cs +++ b/PolyShim/NetCore21/ValueTaskAwaiter.cs @@ -1,4 +1,5 @@ #if FEATURE_TASK +// Can be provided natively or by a compatibility package #if !FEATURE_VALUETASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore21/ValueTaskSourceOnCompletedFlags.cs b/PolyShim/NetCore21/ValueTaskSourceOnCompletedFlags.cs index 1ce9075e..d081b6b9 100644 --- a/PolyShim/NetCore21/ValueTaskSourceOnCompletedFlags.cs +++ b/PolyShim/NetCore21/ValueTaskSourceOnCompletedFlags.cs @@ -1,4 +1,5 @@ #if FEATURE_TASK +// Can be provided natively or by a compatibility package #if !FEATURE_VALUETASK_SOURCES #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore21/ValueTaskSourceStatus.cs b/PolyShim/NetCore21/ValueTaskSourceStatus.cs index 85125737..c41be4c2 100644 --- a/PolyShim/NetCore21/ValueTaskSourceStatus.cs +++ b/PolyShim/NetCore21/ValueTaskSourceStatus.cs @@ -1,4 +1,5 @@ #if FEATURE_TASK +// Can be provided natively or by a compatibility package #if !FEATURE_VALUETASK_SOURCES #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore30/AsyncIteratorMethodBuilder.cs b/PolyShim/NetCore30/AsyncIteratorMethodBuilder.cs index 28fd9bed..2fae8cb0 100644 --- a/PolyShim/NetCore30/AsyncIteratorMethodBuilder.cs +++ b/PolyShim/NetCore30/AsyncIteratorMethodBuilder.cs @@ -1,4 +1,5 @@ #if !FEATURE_ASYNCINTERFACES +// Task infrastructure is required for async method return types #if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore30/ConfiguredCancelableAsyncEnumerable.cs b/PolyShim/NetCore30/ConfiguredCancelableAsyncEnumerable.cs index 34fb5dc9..77c47de4 100644 --- a/PolyShim/NetCore30/ConfiguredCancelableAsyncEnumerable.cs +++ b/PolyShim/NetCore30/ConfiguredCancelableAsyncEnumerable.cs @@ -1,4 +1,5 @@ #if !FEATURE_ASYNCINTERFACES +// Task infrastructure is required for async method return types #if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore30/IAsyncDisposable.cs b/PolyShim/NetCore30/IAsyncDisposable.cs index 2cf6ad3c..69b31384 100644 --- a/PolyShim/NetCore30/IAsyncDisposable.cs +++ b/PolyShim/NetCore30/IAsyncDisposable.cs @@ -1,4 +1,5 @@ #if !FEATURE_ASYNCINTERFACES +// Task infrastructure is required for async method return types #if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore30/IAsyncEnumerable.cs b/PolyShim/NetCore30/IAsyncEnumerable.cs index fd355fcb..85ab8354 100644 --- a/PolyShim/NetCore30/IAsyncEnumerable.cs +++ b/PolyShim/NetCore30/IAsyncEnumerable.cs @@ -1,4 +1,5 @@ #if !FEATURE_ASYNCINTERFACES +// Task infrastructure is required for async method return types #if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore30/Process.cs b/PolyShim/NetCore30/Process.cs index 9adc4982..90e7cc9e 100644 --- a/PolyShim/NetCore30/Process.cs +++ b/PolyShim/NetCore30/Process.cs @@ -1,4 +1,5 @@ #if (NETCOREAPP && !NETCOREAPP3_0_OR_GREATER) || (NET35_OR_GREATER) || (NETSTANDARD) +#if FEATURE_PROCESS #nullable enable #pragma warning disable CS0436 @@ -13,9 +14,9 @@ #endif internal static class MemberPolyfills_NetCore30_Process { -#if FEATURE_PROCESS && FEATURE_MANAGEMENT extension(Process process) { +#if FEATURE_MANAGEMENT // https://learn.microsoft.com/dotnet/api/system.diagnostics.process.kill#system-diagnostics-process-kill(system-boolean) public void Kill(bool entireProcessTree) { @@ -62,7 +63,8 @@ static void KillProcessTree(int processId) KillProcessTree(process.Id); } - } #endif + } } #endif +#endif diff --git a/PolyShim/NetCore30/RandomNumberGenerator.cs b/PolyShim/NetCore30/RandomNumberGenerator.cs index 4e90b995..fe56f02b 100644 --- a/PolyShim/NetCore30/RandomNumberGenerator.cs +++ b/PolyShim/NetCore30/RandomNumberGenerator.cs @@ -32,7 +32,7 @@ public static int GetInt32(int fromInclusive, int toExclusive) var buffer = ArrayPool.Shared.Rent(4); try { - uint result; + var result = 0U; do { RandomNumberGeneratorEx.Instance.GetBytes(buffer, 0, 4); diff --git a/PolyShim/NetCore30/Stream.cs b/PolyShim/NetCore30/Stream.cs index 86ada028..f6165ad9 100644 --- a/PolyShim/NetCore30/Stream.cs +++ b/PolyShim/NetCore30/Stream.cs @@ -14,17 +14,16 @@ internal static class MemberPolyfills_NetCore30_Stream { extension(Stream stream) { + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.stream.disposeasync public async ValueTask DisposeAsync() { -#if FEATURE_ASYNCINTERFACES if (stream is IAsyncDisposable asyncDisposable) { await asyncDisposable.DisposeAsync(); return; } -#endif try { diff --git a/PolyShim/NetCore30/TaskAsyncEnumerableExtensions.cs b/PolyShim/NetCore30/TaskAsyncEnumerableExtensions.cs index b061048b..811c9609 100644 --- a/PolyShim/NetCore30/TaskAsyncEnumerableExtensions.cs +++ b/PolyShim/NetCore30/TaskAsyncEnumerableExtensions.cs @@ -1,4 +1,5 @@ #if !FEATURE_ASYNCINTERFACES +// Task infrastructure is required for async method return types #if FEATURE_TASK #nullable enable #pragma warning disable CS0436 diff --git a/PolyShim/NetCore30/TextWriter.cs b/PolyShim/NetCore30/TextWriter.cs index 04513198..c8677566 100644 --- a/PolyShim/NetCore30/TextWriter.cs +++ b/PolyShim/NetCore30/TextWriter.cs @@ -14,17 +14,16 @@ internal static class MemberPolyfills_NetCore30_TextWriter { extension(TextWriter writer) { + // Task infrastructure is required for async method support #if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.io.textwriter.disposeasync public async ValueTask DisposeAsync() { -#if FEATURE_ASYNCINTERFACES if (writer is IAsyncDisposable asyncDisposable) { await asyncDisposable.DisposeAsync(); return; } -#endif try { diff --git a/PolyShim/NetCore30/Timer.cs b/PolyShim/NetCore30/Timer.cs index 30965b2f..6ef5d748 100644 --- a/PolyShim/NetCore30/Timer.cs +++ b/PolyShim/NetCore30/Timer.cs @@ -13,7 +13,8 @@ internal static class MemberPolyfills_NetCore30_Timer { extension(Timer timer) { -#if FEATURE_ASYNCINTERFACES + // Task infrastructure is required for async method support +#if FEATURE_TASK // https://learn.microsoft.com/dotnet/api/system.threading.timer.disposeasync public ValueTask DisposeAsync() {