Skip to content

Add new static extension polyfills using C# 14 syntax#515

Merged
SimonCropp merged 4 commits intoSimonCropp:mainfrom
thomhurst:feat/new-static-extension-polyfills
Apr 5, 2026
Merged

Add new static extension polyfills using C# 14 syntax#515
SimonCropp merged 4 commits intoSimonCropp:mainfrom
thomhurst:feat/new-static-extension-polyfills

Conversation

@thomhurst
Copy link
Copy Markdown
Contributor

Summary

  • New polyfills using C# 14 extension(Type) syntax so consumers call APIs naturally on the original types:
    • Stopwatch.GetElapsedTime (NET7+)
    • Directory.CreateTempSubdirectory (NET7+)
    • char.IsBetween (NET8+)
    • TimeSpan.FromDays/FromHours/FromMinutes/FromSeconds/FromMilliseconds/FromMicroseconds integer overloads (NET9+)
    • string.Concat ReadOnlySpan<string?> and ReadOnlySpan<object?> overloads (NET9+)
    • Guid.AllBitsSet (NET10+)
    • Task.WhenAll/WhenAny ReadOnlySpan<Task> overloads (NET10+)
  • Refactored Polyfill_Directory.cs to use extension(Directory) — consumers now call Directory.EnumerateFiles(...) instead of Polyfill.EnumerateFiles(...)
  • Includes tests, Consume entries, and regenerated Split files + api_list

Test plan

  • Core Polyfill project builds with 0 warnings/errors
  • All tests pass across all frameworks (netcoreapp3.1, net48, net5.0–net11.0)
  • Consume project compiles on all target frameworks
  • ApiBuilderTests pass — Split files and api_list.include.md regenerated
  • LF line endings verified on all new/modified files

Add polyfills for newer .NET APIs using the C# 14 `extension(Type)` syntax
so consumers can call them naturally (e.g. `Directory.CreateTempSubdirectory()`
instead of `Polyfill.CreateTempSubdirectory()`).

New polyfills:
- Stopwatch.GetElapsedTime (NET7+)
- Directory.CreateTempSubdirectory (NET7+)
- char.IsBetween (NET8+)
- TimeSpan.FromDays/FromHours/FromMinutes/FromSeconds/FromMilliseconds/FromMicroseconds integer overloads (NET9+)
- string.Concat ReadOnlySpan<string?>/ReadOnlySpan<object?> overloads (NET9+)
- Guid.AllBitsSet (NET10+)
- Task.WhenAll/WhenAny ReadOnlySpan overloads (NET10+)

Refactored:
- Polyfill_Directory.cs: wrapped in extension(Directory) block so consumers
  call Directory.EnumerateFiles() instead of Polyfill.EnumerateFiles()

Includes tests, Consume entries, and regenerated Split files.
…lity

The extension(Directory) refactor would have broken existing consumers
who call Polyfill.EnumerateFiles(...) etc. Reverting to keep the old
API surface intact.
Remove duplicate nested #if !NET9_0_OR_GREATER directives that were
already covered by the outer guard wrapping the extension(File) block.
@SimonCropp SimonCropp added this to the 10.0.0 milestone Apr 5, 2026
@SimonCropp
Copy link
Copy Markdown
Owner

@thomhurst LGTM thanks

@SimonCropp SimonCropp merged commit a0aeaae into SimonCropp:main Apr 5, 2026
1 of 2 checks passed
This was referenced Apr 6, 2026
This was referenced Apr 6, 2026
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.

2 participants