This guide shows how to install StrongTypeIdGenerator and generate your first strongly typed identifier.
Install the main package:
dotnet add package StrongTypeIdGeneratorOptional JSON integration package:
dotnet add package StrongTypeIdGenerator.Jsonusing StrongTypeIdGenerator;
[StringId]
public sealed partial class ProductId
{
}Build the project. The source generator creates members on ProductId.
For scalar IDs ([StringId] and [GuidId]), generated members include:
- Constructor
Valueproperty (or custom property name)Unspecified- Equality and comparison support
ToStringand formatting overload- Implicit conversions
- Nested
TypeConverter
[GuidId]
public sealed partial class UserId
{
}[CombinedId(typeof(UserId), "UserId", typeof(ProductId), "ProductId")]
public sealed partial class UserProductId
{
}Combined IDs produce one property per component, comparison/equality, formatting, and TypeConverter support.