Skip to content

refactor: use collection expressions for empty list initializers#849

Merged
laurentiu021 merged 1 commit into
mainfrom
refactor/r8-collection-expressions
Jun 11, 2026
Merged

refactor: use collection expressions for empty list initializers#849
laurentiu021 merged 1 commit into
mainfrom
refactor/r8-collection-expressions

Conversation

@laurentiu021

Copy link
Copy Markdown
Owner

What

Audit Round 8 (.NET 10 modernization). Replaced var x = new List<T>() with List<T> x = [] across 7 files (8 sites): WingetTableParser, FileShredderService, TemperatureService (×2), WindowsUpdateService, BulkInstallerViewModel, LogsViewModel, TracerouteViewModel.

Behavior guarantee (Protocol Q)

Byte-identical. A collection expression [] for a List<T> target compiles to the same new List<T>() construction — pure compiler sugar. The declaration uses an explicit type because a collection expression needs a target type (it can't be inferred from var).

Scope note

I deliberately limited this to the unambiguous empty-list initializers. The blanket catch (Exception) clauses (also in the R8 backlog) are not included — converting those changes which exceptions are caught and needs per-site judgement (many are intentional top-of-command catch-alls that keep the UI from crashing), so they don't belong in a mechanical, behavior-identical sweep.

Verification

  • Build: main + unit + integration, 0 errors / 0 warnings (Release).
  • Diff is exactly 8 insertions / 8 deletions, all list-init lines.

Notes

  • refactor: — no version bump, no release, no CHANGELOG entry required.

Replaced 'var x = new List<T>()' with 'List<T> x = []' across 7 files (8 sites:
WingetTableParser, FileShredderService, TemperatureService x2, WindowsUpdateService,
BulkInstallerViewModel, LogsViewModel, TracerouteViewModel).

Pure .NET 10 idiom modernization — the collection expression compiles to the
same List<T> construction, so behavior is byte-identical. The explicit type is
required because a collection expression needs a target type (can't infer from var).
@laurentiu021 laurentiu021 merged commit d85355c into main Jun 11, 2026
5 of 6 checks passed
@laurentiu021 laurentiu021 deleted the refactor/r8-collection-expressions branch June 11, 2026 11:40
laurentiu021 added a commit that referenced this pull request Jun 11, 2026
…al count) (#850)

GetIcon_SamePath_UsesCachedResult and ClearCache_ResetsCount asserted on the
global CacheCount of the shared static icon cache. That cache is touched by
tests in OTHER collections (via VMs that call GetIcon), running in parallel, so
an entry added between the test's two count reads broke the assertion. The
SamePath test failed once in PR #849's CI for exactly this reason — unrelated to
that PR's change.

Added an internal IconExtractorService.IsCached(path) that checks one normalized
key, and rewrote both tests to assert per-key caching (cached after first call,
dropped after ClearCache) instead of the global count. Deterministic regardless
of what other parallel tests do to the shared cache. Production behavior
unchanged (the helper is additive; InternalsVisibleTo already declared).

Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant