Skip to content

Latest commit

 

History

History
69 lines (49 loc) · 1.28 KB

File metadata and controls

69 lines (49 loc) · 1.28 KB

Getting Started

This guide shows how to install StrongTypeIdGenerator and generate your first strongly typed identifier.

Install

Install the main package:

dotnet add package StrongTypeIdGenerator

Optional JSON integration package:

dotnet add package StrongTypeIdGenerator.Json

Create your first ID type

using StrongTypeIdGenerator;

[StringId]
public sealed partial class ProductId
{
}

Build the project. The source generator creates members on ProductId.

What gets generated

For scalar IDs ([StringId] and [GuidId]), generated members include:

  • Constructor
  • Value property (or custom property name)
  • Unspecified
  • Equality and comparison support
  • ToString and formatting overload
  • Implicit conversions
  • Nested TypeConverter

Guid example

[GuidId]
public sealed partial class UserId
{
}

Combined ID example

[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.

Next steps