Refactor: var consistency, guard ordering, and other style improvements#118
Refactor: var consistency, guard ordering, and other style improvements#118
Conversation
…arget-typed new Agent-Logs-Url: https://github.com/Tyrrrz/PolyShim/sessions/9380a44e-217f-4733-8885-0bf8cbd4c74a Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/PolyShim/sessions/c8047f61-bf51-4058-824e-7575521b8389 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
|
@copilot resolve the merge conflicts in this pull request |
| @@ -1,4 +1,5 @@ | |||
| #if FEATURE_TASK | |||
| // ValueTask is provided via the System.Threading.Tasks.Extensions NuGet package when available. | |||
There was a problem hiding this comment.
Replace this and other similar comments with just:
// Can be provided natively or by a compatibility package
| public Span(T[]? array) | ||
| : this(array, 0, array?.Length ?? 0) { } | ||
|
|
||
| // Unsafe code is required for the pointer-accepting constructor. |
There was a problem hiding this comment.
Remove periods from one-line comments similar to this one @copilot
| internal static class MemberPolyfills_NetCore30_Process | ||
| { | ||
| // Both process and management features are required for process tree support. | ||
| #if FEATURE_PROCESS && FEATURE_MANAGEMENT |
There was a problem hiding this comment.
The process guard should be file-wide since it applies to everything in this file @copilot
…ew throughout Agent-Logs-Url: https://github.com/Tyrrrz/PolyShim/sessions/7c093ed3-1f31-4467-8a98-9819dcd32010 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
|
@copilot retry |
|
@copilot merge in latest prime, re-check added/modified files, and then retry whatever you failed to do last time. |
…sistency-in-codebase # Conflicts: # PolyShim/NetCore21/ManualResetValueTaskSourceCore.cs Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
…d scope Agent-Logs-Url: https://github.com/Tyrrrz/PolyShim/sessions/f62bd0e1-a337-43bb-b89c-027a12950fce Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Done in 9b87704:
|
|
@copilot can you debug the build error? |
There was a problem hiding this comment.
Pull request overview
This PR applies repository-wide style/consistency refactors across PolyShim polyfill sources and tests, primarily standardizing var usage, adding clarifying feature-guard comments, and adopting target-typed new where applicable.
Changes:
- Standardize locals to
varwith explicit initializers/casts (including tests for Span/Memory and numeric literals). - Add/adjust feature-guard ordering and explanatory comments around
FEATURE_TASKand related polyfill conditions. - Replace explicit constructor calls with target-typed
newfor consistency.
Reviewed changes
Copilot reviewed 62 out of 62 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| PolyShim/NetCore30/Timer.cs | Removes FEATURE_ASYNCINTERFACES guard from DisposeAsync (now unconditional). |
| PolyShim/NetCore30/TextWriter.cs | Wraps async dispose support under FEATURE_TASK; removes inner async-interface guard. |
| PolyShim/NetCore30/TaskAsyncEnumerableExtensions.cs | Adds explanatory comment before FEATURE_TASK guard. |
| PolyShim/NetCore30/Stream.cs | Wraps async dispose support under FEATURE_TASK; removes inner async-interface guard. |
| PolyShim/NetCore30/RandomNumberGenerator.cs | Switches explicit uint local to var with initializer. |
| PolyShim/NetCore30/Process.cs | Reorders/adjusts feature guards (FEATURE_PROCESS, FEATURE_MANAGEMENT). |
| PolyShim/NetCore30/IAsyncEnumerable.cs | Adds explanatory comment before FEATURE_TASK guard. |
| PolyShim/NetCore30/IAsyncDisposable.cs | Adds explanatory comment before FEATURE_TASK guard. |
| PolyShim/NetCore30/ConfiguredCancelableAsyncEnumerable.cs | Adds explanatory comment before FEATURE_TASK guard. |
| PolyShim/NetCore30/AsyncIteratorMethodBuilder.cs | Adds explanatory comment before FEATURE_TASK guard. |
| PolyShim/NetCore21/ValueTaskSourceStatus.cs | Adds comment clarifying native vs package availability. |
| PolyShim/NetCore21/ValueTaskSourceOnCompletedFlags.cs | Adds comment clarifying native vs package availability. |
| PolyShim/NetCore21/ValueTaskAwaiter.cs | Adds comment clarifying native vs package availability. |
| PolyShim/NetCore21/ValueTask.cs | Adds comment clarifying native vs package availability. |
| PolyShim/NetCore21/TextWriter.cs | Adds comment before FEATURE_TASK-guarded async members. |
| PolyShim/NetCore21/TextReader.cs | Adds comment before FEATURE_TASK-guarded async members. |
| PolyShim/NetCore21/Stream.cs | Adds comments before FEATURE_TASK-guarded async members. |
| PolyShim/NetCore21/Span.cs | Adds comment before ALLOW_UNSAFE_BLOCKS guarded constructor. |
| PolyShim/NetCore21/IValueTaskSource.cs | Adds comment clarifying native vs package availability. |
| PolyShim/NetCore21/ConfiguredValueTaskAwaitable.cs | Adds comment clarifying native vs package availability; uses target-typed new. |
| PolyShim/NetCore21/AsyncValueTaskMethodBuilder.cs | Adds comment clarifying native vs package availability. |
| PolyShim/NetCore20/Task.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/NetCore20/File.cs | Adds comment before FEATURE_TASK async members; switches int locals to var init. |
| PolyShim/NetCore10/Version.cs | Uses target-typed new in TryParse. |
| PolyShim/NetCore10/TaskCompletionSource.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/NetCore10/Task.cs | Moves FEATURE_TASK under TFM guard; uses var + target-typed new in Delay impl. |
| PolyShim/NetCore10/SemaphoreSlim.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/NetCore10/ParallelOptions.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/NetCore10/AggregateException.cs | Uses target-typed new in Flatten. |
| PolyShim/Net90/Task.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/Net90/Lock.cs | Uses target-typed new for Scope construction. |
| PolyShim/Net90/File.cs | Adds comment before FEATURE_TASK async members. |
| PolyShim/Net80/TimeProvider.cs | Uses target-typed new; changes async dispose guard to FEATURE_TASK. |
| PolyShim/Net80/TextWriter.cs | Adds comment before FEATURE_TASK async members. |
| PolyShim/Net80/Parallel.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/Net80/ITimer.cs | Changes async-disposable base-interface guard to FEATURE_TASK; adds comment. |
| PolyShim/Net80/CancellationTokenSource.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/Net70/UIntPtr.cs | Uses target-typed new in TryParse. |
| PolyShim/Net70/TextReader.cs | Adds comment before FEATURE_TASK async members. |
| PolyShim/Net70/Stream.cs | Adds comments before FEATURE_TASK async members. |
| PolyShim/Net70/Stopwatch.cs | Uses target-typed new for TimeSpan construction. |
| PolyShim/Net70/IntPtr.cs | Uses target-typed new in TryParse. |
| PolyShim/Net70/File.cs | Adds comment before FEATURE_TASK async members. |
| PolyShim/Net60/Task.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/Net60/Random.cs | Switches explicit ulong local to var init; uses new() for Random. |
| PolyShim/Net60/Parallel.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/Net50/UIntPtr.cs | Uses target-typed new in TryParse. |
| PolyShim/Net50/TaskCompletionSourceOfT.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/Net50/TaskCompletionSource.cs | Moves FEATURE_TASK under TFM guard; adds explanatory comment. |
| PolyShim/Net50/Process.cs | Adds FEATURE_TASK-guard comment for async members. |
| PolyShim/Net50/Interlocked.cs | Switches explicit locals to var + initializer; adds unsafe-guard comments. |
| PolyShim/Net50/IntPtr.cs | Uses target-typed new in TryParse. |
| PolyShim/Net50/HttpContent.cs | Moves FEATURE_HTTPCLIENT under TFM guard; adds FEATURE_TASK-guard comment. |
| PolyShim/Net50/HttpClient.cs | Moves FEATURE_HTTPCLIENT under TFM guard; adds FEATURE_TASK-guard comment. |
| PolyShim.Tests/NetCore21/SpanTests.cs | Converts explicit Span locals to var + cast for collection expressions/stackalloc. |
| PolyShim.Tests/NetCore21/ReadOnlySpanTests.cs | Converts explicit ReadOnlySpan/Span locals to var + cast. |
| PolyShim.Tests/NetCore21/ReadOnlyMemoryTests.cs | Converts explicit ReadOnlyMemory/Memory locals to var + cast. |
| PolyShim.Tests/NetCore21/MemoryTests.cs | Converts explicit Memory locals to var + cast. |
| PolyShim.Tests/NetCore21/MemoryExtensionsTests.cs | Converts explicit Span/Memory locals to var + cast. |
| PolyShim.Tests/Net90/FileTests.cs | Converts explicit ReadOnlySpan/ReadOnlyMemory locals to var + cast. |
| PolyShim.Tests/Net80/RandomTests.cs | Converts explicit Span/ReadOnlySpan locals to var + cast. |
| PolyShim.Tests/Net50/InterlockedTests.cs | Converts explicit numeric locals to var with casts for literal typing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…atting Agent-Logs-Url: https://github.com/Tyrrrz/PolyShim/sessions/d201f0c6-25ff-4f63-be6c-37f2f66d64dc Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Fixed in 0086dd7. Two issues:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## prime #118 +/- ##
==========================================
- Coverage 90.83% 90.72% -0.11%
==========================================
Files 285 286 +1
Lines 4962 4982 +20
Branches 404 406 +2
==========================================
+ Hits 4507 4520 +13
- Misses 365 370 +5
- Partials 90 92 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
PolyShim/Net50/Interlocked.cs— replace explicit-typeint/long current/originalwithvar+ initializersPolyShim/Net60/Random.cs— replaceulong ulongRand;withvar ulongRand = 0UL;PolyShim/NetCore20/File.cs— replaceint charsRead;(×2) withvar charsRead = 0;PolyShim/NetCore30/RandomNumberGenerator.cs— replaceuint result;withvar result = 0U;PolyShim.Tests/Net50/InterlockedTests.cs— replaceuint ui,long l,ulong ulwithvar+ castsPolyShim/NetCore10/Task.cs— replaceTimer? timer = null;andCancellationTokenRegistration registration = default;withvarforms; usenew(...)for Timer assignmentPolyShim/Net90/Lock.cs—return new Scope(this);(×2) →return new(this);PolyShim/NetCore10/AggregateException.cs—return new AggregateException(...)→return new(...)PolyShim/Net80/TimeProvider.cs—return new DateTimeOffset(...)and_timer = new Timer(...)→ target-typed newPolyShim/Net70/Stopwatch.cs—return new TimeSpan(...)(×3) →return new(...)PolyShim/Net50/IntPtr.cs—result = new IntPtr(...)(×2) →result = new(...)PolyShim/Net50/UIntPtr.cs—result = new UIntPtr(...)(×2) →result = new(...)PolyShim/Net70/IntPtr.cs—result = new IntPtr(...)(×2) →result = new(...)PolyShim/Net70/UIntPtr.cs—result = new UIntPtr(...)(×2) →result = new(...)PolyShim/NetCore10/Version.cs—result = new Version(input);→result = new(input);PolyShim/Net60/Random.cs—new Random()→new()PolyShim.Tests/NetCore21/SpanTests.cs—Span<byte> ... = [...]→var ... = (Span<byte>)[...]PolyShim.Tests/NetCore21/ReadOnlySpanTests.cs—ReadOnlySpan<byte> ... = [...]→var ... = (ReadOnlySpan<byte>)[...]PolyShim.Tests/NetCore21/MemoryTests.cs—Memory<byte> ... = new byte[]→var ... = (Memory<byte>)new byte[]PolyShim.Tests/NetCore21/ReadOnlyMemoryTests.cs—ReadOnlyMemory<byte> ... = new byte[]→var ... = (ReadOnlyMemory<byte>)new byte[]PolyShim.Tests/NetCore21/MemoryExtensionsTests.cs—Span/Memory explicit types→var + castPolyShim.Tests/Net80/RandomTests.cs—ReadOnlySpan<int>/Span<int>→var + castPolyShim.Tests/Net90/FileTests.cs—ReadOnlySpan/Memory→var + cast