Add ISpanFormattable/IFormattable support to ChainablePath - #158
Merged
Conversation
Adds interpolated-string-handler support so paths written into
DefaultInterpolatedStringHandler (e.g. $"{path}") avoid boxing and
an intermediate string allocation.
- IFormattable.ToString(format, provider) is implemented unconditionally
on all target frameworks, since a ChainablePath has no format
specifiers of its own and just returns the underlying path.
- ISpanFormattable.TryFormat is implemented only under NET6_0_OR_GREATER,
since that interface does not exist on netstandard2.0/2.1 or net47.
- Added unit tests covering interpolated-string usage, ToString(format,
provider), and TryFormat success/destination-too-small cases.
- Updated approved public API snapshots for all four target frameworks.
Fixes #148
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #148
Summary
Adds interpolated-string-handler support to
ChainablePathso writing a path into an interpolated string (e.g.$"{path}") orDefaultInterpolatedStringHandleravoids boxing the struct and building an intermediate string.Design decisions
IFormattable.ToString(string?, IFormatProvider?)is implemented unconditionally on all four target frameworks (netstandard2.0,netstandard2.1,net47,net8.0), since it's available everywhere. AChainablePathhas no format specifiers of its own, soformat/formatProviderare ignored and the underlying path string is returned as-is.ISpanFormattable.TryFormat(...)is implemented only under#if NET6_0_OR_GREATER, reusing the existing#if PATHY_PUBLICconditional-compilation pattern already used in this file.ISpanFormattabledoesn't exist in the BCL contracts fornetstandard2.0/netstandard2.1/net47(confirmed via a build failure when initially gated onNETSTANDARD2_1_OR_GREATER), so it's gated to .NET 6+ only, which covers this repo'snet8.0target.TryFormatis a thin span-copy fast path (path.AsSpan().TryCopyTo(destination)), returningfalseandcharsWritten = 0when the destination is too small, perISpanFormattableconventions.Null/Emptyare backed bystring.Empty, so both format to an empty span/string without throwing.Tests
Added to
Pathy.Specs/ChainablePathSpecs.cs:$"{path}"produces the correct string, exercisingDefaultInterpolatedStringHandler.AppendFormatted).ToString(format, provider)returns the underlying path regardless of format/provider.TryFormatsuccess case (destination large enough).TryFormatfailure case (destination too small) — both gated under#if NET6_0_OR_GREATERto match thenet8.0/net472specs targets.API approval
This adds new public members to
ChainablePath(exposed publicly viaPATHY_PUBLICwhen consumed as content files). Updated all fourPathy.ApiVerificationTests/ApprovedApi/pathy.*.verified.txtsnapshots to match.dotnet test Pathy.ApiVerificationTestspasses (8/8) anddotnet test Pathy.Specspasses (113/113 on net8.0).Note on base branch
CONTRIBUTING.md instructs PRs to target a
developbranch, but nodevelopbranch currently exists in this GitHub repository (onlymain, which is also the repo's default branch). Opening this PR againstmaininstead.Note on approval status
This issue is only labeled
enhancement, notapi-approved, and CONTRIBUTING.md normally requires the latter before opening an API-changing PR. Proceeding anyway at the explicit request of the repo owner, who is coordinating this work — flagging here for visibility since this implements an as-yet-unapproved API proposal.