Skip to content

Implement ISpanParsable<Version> on System.Version - #135295

Open
SkyDevLab wants to merge 2 commits into
dotnet:mainfrom
SkyDevLab:feature/125026-version-ispanparsable
Open

SkyDevLab wants to merge 2 commits into
dotnet:mainfrom
SkyDevLab:feature/125026-version-ispanparsable

Conversation

@SkyDevLab

Copy link
Copy Markdown
Contributor

Fixes #125026

Customer Impact

As approved in API review #125026, System.Version previously implemented IUtf8SpanParsable, but not ISpanParsable (nor IParsable).
This PR implements ISpanParsable (and by extension IParsable) explicitly on System.Version.

Proposed Changes

  1. System.Private.CoreLib (src/libraries/System.Private.CoreLib/src/System/Version.cs):
    • Added ISpanParsable to the interface implementation list on System.Version.
    • Added explicit interface implementations for:
      • static Version IParsable.Parse(string s, IFormatProvider? provider)
      • static bool IParsable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [NotNullWhen(true)] out Version? result)
      • static Version ISpanParsable.Parse(ReadOnlySpan s, IFormatProvider? provider)
      • static bool ISpanParsable.TryParse(ReadOnlySpan s, IFormatProvider? provider, [NotNullWhen(true)] out Version? result)
    • Factored common contract parsing validation through a shared ParseHelper routine (matching the existing IUtf8SpanParsable.Parse error semantics to ensure FormatException is thrown on invalid inputs).
  2. System.Runtime Ref Assembly (src/libraries/System.Runtime/ref/System.Runtime.cs):
    • Added IParsable<System.Version> and ISpanParsable<System.Version> to System.Version interface list and declared the explicit interface methods.
  3. Unit Tests (src/libraries/System.Runtime/tests/System.Runtime.Tests/System/VersionTests.cs):
    • Added comprehensive tests for generic IParsable and ISpanParsable parsing, null input validation, invalid input formatting exceptions, and trailing dot edge cases.

Validation

  • System.Private.CoreLib.csproj builds cleanly (0 warnings, 0 errors).
  • System.Runtime/ref/System.Runtime.csproj builds cleanly (0 warnings, 0 errors).
  • System.Runtime.Tests.csproj compiles cleanly with the new test suite referencing the updated contracts.
  • Formatting verified clean with git diff --check.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 6, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

}
}

private static T GenericParse<T>(string s, IFormatProvider? provider = null) where T : IParsable<T> =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these are already available in ParsableHelper, SpanParsableHelper and Utf8SpanParsableHelper.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use the shared ParsableHelper<T>, SpanParsableHelper<T>, and Utf8SpanParsableHelper<T> test classes in commit 4c30ddb. Thanks!

@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintentional BOM change (removal)? I believe this should be reverted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored the UTF-8 BOM on Version.cs in commit 4c30ddb. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Runtime community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Implement ISpanParsable on System.Version

2 participants