Thinktecture.Runtime.Extensions.SourceGenerator 10.3.0

dotnet add package Thinktecture.Runtime.Extensions.SourceGenerator --version 10.3.0
                    
NuGet\Install-Package Thinktecture.Runtime.Extensions.SourceGenerator -Version 10.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Thinktecture.Runtime.Extensions.SourceGenerator" Version="10.3.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Thinktecture.Runtime.Extensions.SourceGenerator" Version="10.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Thinktecture.Runtime.Extensions.SourceGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Thinktecture.Runtime.Extensions.SourceGenerator --version 10.3.0
                    
#r "nuget: Thinktecture.Runtime.Extensions.SourceGenerator, 10.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Thinktecture.Runtime.Extensions.SourceGenerator@10.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Thinktecture.Runtime.Extensions.SourceGenerator&version=10.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Thinktecture.Runtime.Extensions.SourceGenerator&version=10.3.0
                    
Install as a Cake Tool

Build TestResults NuGet Downloads

Thinktecture.Runtime.Extensions

A .NET library that uses Roslyn Source Generators, Analyzers, and CodeFixes to give you Smart Enums, Value Objects, and Discriminated Unions with built-in validation, exhaustive pattern matching, and first-class framework integration -- so you write the declaration and the generator handles the boilerplate.

Quick Start

Install-Package Thinktecture.Runtime.Extensions

Smart Enums

Type-safe enumerations that go beyond plain enum. Each item can carry its own data and behavior, the generator produces equality, parsing, Switch/Map, and serializer integration automatically.

[SmartEnum<string>]
public partial class ShippingMethod
{
   public static readonly ShippingMethod Standard = new("STANDARD", basePrice: 5.99m, estimatedDays: 5);
   public static readonly ShippingMethod Express = new("EXPRESS", basePrice: 15.99m, estimatedDays: 2);

   public decimal CalculatePrice(decimal weight) => _basePrice + weight;
}

Full documentation -- customization, real-world examples, performance tips, framework integration.

Value Objects

Immutable domain primitives that eliminate primitive obsession. Wrap a single value or multiple properties, add validation, and get factory methods, equality, conversion operators, and serialization for free.

Simple value object

[ValueObject<decimal>]
public partial struct Amount
{
    static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref decimal value)
    {
        if (value < 0)
            validationError = new ValidationError("Amount cannot be negative");
    }
}

Complex value object

[ComplexValueObject]
public partial class Boundary
{
    public decimal Lower { get; }
    public decimal Upper { get; }

    static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref decimal lower, ref decimal upper)
    {
        if (lower > upper)
            validationError = new ValidationError("Lower must be less than or equal to Upper");
    }
}

Full documentation -- simple & complex value objects, customization, framework integration.

Discriminated Unions

Model "one of" types with full type safety. Choose ad-hoc unions for quick combinations (Union<T1, T2>) or regular unions (Union) for rich domain modeling with exhaustive Switch/Map.

Ad-hoc union

[Union<string, int>]
public partial struct TextOrNumber;

Regular union

[Union]
public partial record Result<T>
{
    public sealed record Success(T Value) : Result<T>;
    public sealed record Failure(string Error) : Result<T>;
}

Full documentation -- ad-hoc unions, regular unions, customization, framework integration.

Framework Integration

All generated types integrate with the .NET ecosystem out of the box:

  • System.Text.Json -- zero-allocation span-based serialization on .NET 9+
  • Entity Framework Core -- value converters for EF Core 8, 9, and 10
  • ASP.NET Core -- model binding and Minimal API parameter binding via IParsable<T>
  • MessagePack -- binary serialization support
  • Newtonsoft.Json -- JsonConverter support
  • Swashbuckle / OpenAPI -- schema and operation filters

AI Coding Assistants

Two complementary ways to give an AI coding assistant accurate knowledge of this library:

Agent skill -- a curated guidance package bundled in this repository that teaches AI coding agents (Claude Code, Cursor, and others) how to design and implement Smart Enums, Value Objects, Discriminated Unions, and Object Factories with this library. Install it into your project with the skills CLI:

npx skills@latest add PawelGerr/Thinktecture.Runtime.Extensions

This copies the skill into .claude/skills/ (or the equivalent folder for your agent). Add -g to install it globally for all your projects.

Context7 (MCP) -- this library's documentation is indexed by Context7. Agents with the Context7 MCP server configured can pull current docs on demand; reference the library ID /pawelgerr/thinktecture.runtime.extensions (or add use context7 to your prompt).

Full documentation -- what the skill covers, install scopes, agent targeting, and Context7 usage.

Packages

Package NuGet
Thinktecture.Runtime.Extensions NuGet
Thinktecture.Runtime.Extensions.Json NuGet
Thinktecture.Runtime.Extensions.Newtonsoft.Json NuGet
Thinktecture.Runtime.Extensions.MessagePack NuGet
Thinktecture.Runtime.Extensions.EntityFrameworkCore8 NuGet
Thinktecture.Runtime.Extensions.EntityFrameworkCore9 NuGet
Thinktecture.Runtime.Extensions.EntityFrameworkCore10 NuGet
Thinktecture.Runtime.Extensions.AspNetCore NuGet
Thinktecture.Runtime.Extensions.Swashbuckle NuGet

Requirements

  • C# 11 (or higher) for generated code
  • SDK 8.0.416 (or higher) for building projects

Documentation

Articles

Smart Enums:

Value Objects:

Discriminated Unions:

Migrations

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Thinktecture.Runtime.Extensions.SourceGenerator:

Package Downloads
Thinktecture.Runtime.Extensions

Provides an easy way to implement Smart Enums, Value Objects and Discriminated Unions.

Thinktecture.Runtime.Extensions.Json.SourceGenerator

Source generators for Thinktecture.Runtime.Extensions.Json.

Thinktecture.Runtime.Extensions.MessagePack.SourceGenerator

Source generators for Thinktecture.Runtime.Extensions.MessagePack.

Thinktecture.Runtime.Extensions.Newtonsoft.Json.SourceGenerator

Source generators for Thinktecture.Runtime.Extensions.Newtonsoft.Json.

Thinktecture.Runtime.Extensions.AspNetCore.SourceGenerator

Source generators for Thinktecture.Runtime.Extensions.AspNetCore.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.3.0 0 6/14/2026
10.3.0-beta02 384 5/15/2026
10.3.0-beta01 249 5/14/2026
10.2.0 33,596 4/10/2026
10.2.0-beta03 251 4/7/2026
10.2.0-beta02 261 3/27/2026
10.2.0-beta01 246 3/26/2026
10.1.2 5,905 3/26/2026
10.1.1 931 3/24/2026
10.1.0 3,496 3/12/2026
10.1.0-beta03 243 3/9/2026
10.1.0-beta02 284 3/2/2026
10.1.0-beta01 242 3/1/2026
10.0.0 7,203 2/12/2026
10.0.0-beta04 762 2/9/2026
10.0.0-beta03 3,888 1/13/2026
10.0.0-beta02 6,435 11/30/2025
10.0.0-beta01 1,067 11/19/2025
9.7.1 16,778 11/20/2025
9.7.0 2,324 11/12/2025
Loading failed