Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ For every struct ID, the source generator emits:
- Implicit/explicit conversion operators to/from `TValue`
- `INewable<TSelf>` / `INewable<TSelf, TValue>` implementation
- `New(TValue value)` static factory method
- `New()` (parameterless) for `Guid`- and `Ulid`-backed IDs, using `Guid.NewGuid()` / `Ulid.NewUlid()`
- `New()` (parameterless) for `Guid`- and `Ulid`-backed IDs, using `Guid.CreateVersion7()` on .NET 9+ or `Guid.NewGuid()` on earlier targets / `Ulid.NewUlid()`

## Factory Methods

```csharp
// Guid-backed: parameterless New() generates a new GUID
var userId = UserId.New(); // new UserId(Guid.NewGuid())
// On .NET 9+, uses Guid.CreateVersion7(); earlier targets use Guid.NewGuid()
var userId = UserId.New(); // new UserId(Guid.CreateVersion7()) on .NET 9+
var userId2 = UserId.New(someGuid); // new UserId(someGuid)

// Ulid-backed: parameterless New() generates a new ULID
Expand Down
13 changes: 9 additions & 4 deletions src/StructId/Templates/NewableGuid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
[TStructId]
file partial record struct TSelf(Guid Value)
{
/// <summary>
/// Creates a new instance of <typeparamref name="TSelf"/> with a <see cref="Guid.NewGuid"/>.
/// </summary>
public static TSelf New() => new(Guid.NewGuid());
/// <summary>Creates a new instance with a newly generated <see cref="Guid"/>.</summary>
public static TSelf New()
{
#if NET9_0_OR_GREATER
return new(Guid.CreateVersion7());
#else
return new(Guid.NewGuid());
#endif
}
}
Loading