Typed IDs Module
The Typed IDs module generates strongly-typed ID structs that replace primitive Guid, int, long, and string identifiers with purpose-built value types — preventing accidental misuse, providing built-in equality/comparison/parsing, and supporting configurable serialization converters.
Quick Start
using Deepstaging.Ids;
// 1. Define a typed ID — a Guid-backed struct by default
[TypedId]
public readonly partial struct ArticleId;
// 2. Create, compare, and format
var id = ArticleId.New(); // v7 UUID
var same = ArticleId.Parse(id.ToString());
bool eq = id == same; // true — value equality
Guid raw = (Guid)id; // explicit cast to backing type
ArticleId back = raw; // implicit conversion from backing type
Features
| Feature |
Description |
| Backing types |
Guid (default), int, long, string |
| Value equality |
IEquatable<T>, ==, !=, GetHashCode |
| Parsing |
IParsable<T>, Parse, TryParse, ToString |
| Conversions |
Implicit from backing type, explicit to backing type |
| TypeConverter |
Always generated — binding, serialization, route values |
| JsonConverter |
Opt-in via Converters = IdConverters.JsonConverter |
| EF Core ValueConverter |
Opt-in via Converters = IdConverters.EfCoreValueConverter |
| Profiles |
Assembly-level [TypedIdProfile] for shared defaults |
Pages
| Page |
Description |
| Attributes |
[TypedId], [TypedIdProfile], [StreamId] — configuration and backing types |
| Generated Code |
Full member table, string validation, usage in records/DTOs/dictionaries |
| Effects Composition |
Integration with Data Store and Event Store modules |
| Converters |
TypeConverter, JsonConverter, EF Core ValueConverter |
Diagnostics
| ID |
Severity |
Description |
Code Fix |
| DSID01 |
Error |
TypedId struct must be partial |
Add partial modifier |
| DSID02 |
Warning |
TypedId struct should be readonly |
— |
| DSID03 |
Error |
StreamId requires TypedId |
— |
| DSID04 |
Warning |
StreamId requires Guid or String backing type |
— |
| DSID05 |
Error |
TypedId references unknown profile |
— |
| DSID06 |
Error |
Duplicate default TypedId profile |
— |