Skip to content

Add full suite of interfaces to SequentialGuid & SequentialSqlGuid structs#19

Merged
buvinghausen merged 10 commits intomasterfrom
add_interfaces
Mar 21, 2026
Merged

Add full suite of interfaces to SequentialGuid & SequentialSqlGuid structs#19
buvinghausen merged 10 commits intomasterfrom
add_interfaces

Conversation

@buvinghausen
Copy link
Copy Markdown
Owner

Add interface implementations and implicit operators to SequentialGuid / SequentialSqlGuid

Summary

This PR promotes SequentialGuid and SequentialSqlGuid from simple wrapper structs to first-class .NET citizens by implementing the standard BCL interfaces and adding implicit conversion operators. A shared ISequentialGuid<TSelf> interface captures the common contract.

New: ISequentialGuid<TSelf> interface

Defines the shape shared by both struct types, constraining TSelf : struct, ISequentialGuid<TSelf>:

Target Interfaces
.NET Framework 4.6.2 / .NET Standard 2.0 IFormattable, IComparable, IComparable<TSelf>, IEquatable<TSelf>
.NET 8–9 Adds ISpanFormattable, ISpanParsable<TSelf>
.NET 10+ Adds IUtf8SpanFormattable, IUtf8SpanParsable<TSelf>

A static abstract Create(Guid) factory method (available on .NET 7+) allows generic code to construct either type from a raw Guid.

Interface implementations on both structs

Interface Methods
IComparable CompareTo(object?)
IComparable<TSelf> CompareTo(TSelf)
IEquatable<TSelf> Equals(TSelf) — plus GetHashCode() override
IFormattable ToString(string?, IFormatProvider?)
ISpanFormattable (.NET 6+) TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
IParsable<TSelf> (.NET 7+) Parse(string, IFormatProvider?), TryParse(string?, IFormatProvider?, out TSelf)
ISpanParsable<TSelf> (.NET 7+) Parse(ReadOnlySpan<char>, IFormatProvider?), TryParse(ReadOnlySpan<char>, IFormatProvider?, out TSelf)
IUtf8SpanFormattable (.NET 10+) TryFormat(Span<byte>, out int, ReadOnlySpan<char>, IFormatProvider?)
IUtf8SpanParsable<TSelf> (.NET 10+) Parse(ReadOnlySpan<byte>, IFormatProvider?), TryParse(ReadOnlySpan<byte>, IFormatProvider?, out TSelf)

Comparison operators

Both structs now define <, <=, >, >= operators delegating to CompareTo.

Implicit conversion operators

Conversion Direction
SequentialGuidGuid Both directions
SequentialGuidstring Both directions
SequentialSqlGuidGuid Both directions
SequentialSqlGuidstring Both directions

Updated README

Each package-level README now documents the struct wrappers. A new top-level README.md serves as the repository landing page with CI/NuGet badges and per-package summaries, while each project folder contains its own README packed into the NuGet package.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR promotes SequentialGuid and SequentialSqlGuid to richer, BCL-integrated value types by introducing a shared ISequentialGuid<TSelf> contract, adding parsing/formatting APIs across TFMs, adding comparison operators, and updating/readjusting README packaging and documentation across the repo.

Changes:

  • Add ISequentialGuid<TSelf> with conditional formatting/parsing interface inheritance and (net7+) static abstract Create(Guid).
  • Implement comparable/equatable/formattable/parsable members, comparison operators, and implicit conversions on SequentialGuid / SequentialSqlGuid.
  • Add new per-package READMEs, update root README, and change packing to include project-local README.md in NuGet packages.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/SequentialGuid/ISequentialGuid.cs Introduces shared interface contract with TFM-conditional interface inheritance and factory.
src/SequentialGuid/SequentialGuid.cs Adds interface implementations, operators, implicit conversions, and parse/format APIs.
src/SequentialGuid/SequentialSqlGuid.cs Adds interface implementations, operators, implicit conversions, and parse/format APIs for SQL-byte-order wrapper.
test/SequentialGuid.Tests/SequentialGuidStructTests.cs Adds tests for Parse/TryParse and span formatting/parsing across TFMs.
test/SequentialGuid.Tests/SequentialSqlGuidStructTests.cs Adds tests for Parse/TryParse and span formatting/parsing across TFMs.
src/SequentialGuid/README.md Adds a full package README including new wrapper documentation.
src/SequentialGuid.EntityFrameworkCore/README.md Adds per-package README for EF Core integration.
src/SequentialGuid.MongoDB/README.md Adds per-package README for MongoDB integration.
src/SequentialGuid.NodaTime/README.md Adds per-package README for NodaTime integration.
src/Directory.Build.props Switches NuGet README packing to use project-local README.md.
README.md Reworks root README into repo landing page with package index and summaries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

buvinghausen and others added 7 commits March 21, 2026 11:52
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@buvinghausen buvinghausen merged commit 53e5f8d into master Mar 21, 2026
1 check passed
@buvinghausen buvinghausen deleted the add_interfaces branch March 21, 2026 16:14
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