Skip to content

Consider migrating Directory polyfills to extension(Directory) syntax #516

@thomhurst

Description

@thomhurst

Summary

The Directory polyfill methods in Polyfill_Directory.cs currently use the Polyfill.EnumerateFiles(...) / Polyfill.GetFiles(...) etc. calling convention. With C# 14's extension(Type) syntax, these could be migrated to extension(Directory) so consumers can call Directory.EnumerateFiles(path, pattern, enumerationOptions) directly — matching the native .NET API surface.

Why this needs a major version bump

This would be a breaking change. Any consumer currently calling:

Polyfill.EnumerateFiles(path, pattern, options);
Polyfill.EnumerateDirectories(path, pattern, options);
Polyfill.EnumerateFileSystemEntries(path, pattern, options);
Polyfill.GetFiles(path, pattern, options);
Polyfill.GetDirectories(path, pattern, options);
Polyfill.GetFileSystemEntries(path, pattern, options);

would get a compilation error (CS0103) after upgrading, and would need to change to:

Directory.EnumerateFiles(path, pattern, options);
Directory.EnumerateDirectories(path, pattern, options);
// etc.

Why both patterns can't coexist

C# 14 extension(Directory) block members are still members of the enclosing Polyfill class at the IL level. Having both Polyfill.EnumerateFiles(...) and extension(Directory) { EnumerateFiles(...) } in the same static partial class Polyfill produces CS0111 (duplicate member signatures). So it's one or the other.

Affected methods

  • EnumerateFiles(string, string, EnumerationOptions)
  • EnumerateDirectories(string, string, EnumerationOptions)
  • EnumerateFileSystemEntries(string, string, EnumerationOptions)
  • GetFiles(string, string, EnumerationOptions)
  • GetDirectories(string, string, EnumerationOptions)
  • GetFileSystemEntries(string, string, EnumerationOptions)

Related

PR #515 added several new extension(Type) polyfills but intentionally kept the Directory methods unchanged for backwards compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions