Skip to content

Create polyfill for string.Create#3130

Merged
jnyrup merged 1 commit intofluentassertions:mainfrom
jnyrup:string_extensions
Dec 5, 2025
Merged

Create polyfill for string.Create#3130
jnyrup merged 1 commit intofluentassertions:mainfrom
jnyrup:string_extensions

Conversation

@jnyrup
Copy link
Member

@jnyrup jnyrup commented Dec 3, 2025

string.Create is better than FormattableString.Invariant.
See MA0111 for a benchmark

With C# 14's extension members, we can now polyfill this static method, by creating an extension member directly on the type string.

Note that this isn't a 1:1 polyfill since string.Create uses DefaultInterpolatedStringHandler which isn't available for older TFMs.
So the polyfill just continues using FormattableString.Invariant for older targets.

IMPORTANT

  • If the PR touches the public API, the changes have been approved in a separate issue with the "api-approved" label.
  • The code complies with the Coding Guidelines for C#.
  • The changes are covered by unit tests which follow the Arrange-Act-Assert syntax and the naming conventions such as is used in these tests.
  • If the PR adds a feature or fixes a bug, please update the release notes with a functional description that explains what the change means to consumers of this library, which are published on the website.
  • If the PR changes the public API the changes needs to be included by running AcceptApiChanges.ps1 or AcceptApiChanges.sh.
  • If the PR affects the documentation, please include your changes in this pull request so the documentation will appear on the website.
    • Please also run ./build.sh --target spellcheck or .\build.ps1 --target spellcheck before pushing and check the good outcome

CONTRIBUTOR LICENSE GRANT

By submitting this contribution, the contributor hereby irrevocably grants to the project owners and maintainers a perpetual, worldwide, royalty-free, irrevocable license to use, reproduce, modify, distribute, sublicense, and create derivative works of the contribution for any purpose and under any terms, including proprietary licensing.

The contributor waives any moral rights in the contribution to the extent permitted by law and agrees not to assert any claim of authorship or control over the contribution. The contributor represents that they are the sole author of the contribution and that it is provided free of any third-party claims.

The contributor understands and agrees that the maintainers may, at their sole discretion, use, license, or redistribute the contribution as part of any work and under any terms they choose, without further permission or attribution.

  • I have read the Contributor License Grant and accept the conditions
  • I'm interested in a free license for Fluent Assertions and will share my email address through [email protected]

@coveralls
Copy link

coveralls commented Dec 3, 2025

Pull Request Test Coverage Report for Build 19934963433

Details

  • 12 of 15 (80.0%) changed or added relevant lines in 8 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.005%) to 97.16%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Src/FluentAssertions/Equivalency/EquivalencyValidationContext.cs 0 1 0.0%
Src/FluentAssertions/Equivalency/Steps/EnumerableEquivalencyValidator.cs 4 5 80.0%
Src/FluentAssertions/Polyfill/StringExtensions.cs 0 1 0.0%
Totals Coverage Status
Change from base Build 19871750788: -0.005%
Covered Lines: 12826
Relevant Lines: 13045

💛 - Coveralls

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at [email protected]

@jnyrup jnyrup force-pushed the string_extensions branch from a43d2ac to e8cf909 Compare December 4, 2025 15:48
@jnyrup jnyrup changed the title Create polyfill for string.Create Create polyfill for string.Create Dec 5, 2025
@jnyrup jnyrup merged commit c61f872 into fluentassertions:main Dec 5, 2025
8 checks passed
@jnyrup jnyrup deleted the string_extensions branch December 5, 2025 09:05
This was referenced Mar 16, 2026
This was referenced Mar 19, 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