Thinktecture.Runtime.Extensions
10.1.0-beta01
See the version list below for details.
dotnet add package Thinktecture.Runtime.Extensions --version 10.1.0-beta01
NuGet\Install-Package Thinktecture.Runtime.Extensions -Version 10.1.0-beta01
<PackageReference Include="Thinktecture.Runtime.Extensions" Version="10.1.0-beta01" />
<PackageVersion Include="Thinktecture.Runtime.Extensions" Version="10.1.0-beta01" />
<PackageReference Include="Thinktecture.Runtime.Extensions" />
paket add Thinktecture.Runtime.Extensions --version 10.1.0-beta01
#r "nuget: Thinktecture.Runtime.Extensions, 10.1.0-beta01"
#:package Thinktecture.Runtime.Extensions@10.1.0-beta01
#addin nuget:?package=Thinktecture.Runtime.Extensions&version=10.1.0-beta01&prerelease
#tool nuget:?package=Thinktecture.Runtime.Extensions&version=10.1.0-beta01&prerelease
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 --
JsonConvertersupport - Swashbuckle / OpenAPI -- schema and operation filters
Packages
Requirements
- C# 11 (or higher) for generated code
- SDK 8.0.416 (or higher) for building projects
Documentation
- Smart Enums -- overview, real-world examples, design patterns
- Customization -- attribute settings, equality, comparison, parsable interfaces
- Framework Integration -- JSON, EF Core, ASP.NET Core, MessagePack
- Performance -- span-based JSON, zero-allocation parsing, benchmarks
- Value Objects -- simple & complex value objects, validation
- Customization -- attribute settings, equality comparers, factory methods, operators
- Framework Integration -- JSON, EF Core, ASP.NET Core, MessagePack
- Discriminated Unions -- ad-hoc and regular unions, pattern matching
- Customization -- backing fields, stateless types, constructors
- Framework Integration -- JSON, EF Core, MessagePack
- Object Factories -- custom creation logic for advanced parsing and deserialization
- Analyzer Diagnostics -- reference for all
TTRESGdiagnostic rules - Source Generator Configuration -- MSBuild properties for controlling generator behavior
Articles
Smart Enums:
- Smart Enums: Beyond Traditional Enumerations in .NET
- Smart Enums: Adding Domain Logic to Enumerations in .NET
- Smart Enums in .NET: Integration with Frameworks and Libraries
Value Objects:
- Value Objects: Solving Primitive Obsession in .NET
- Handling Complexity: Introducing Complex Value Objects in .NET
- Value Objects in .NET: Integration with Frameworks and Libraries
- Value Objects in .NET: Enhancing Business Semantics
- Advanced Value Object Patterns in .NET
Discriminated Unions:
- Discriminated Unions: Representation of Alternative Types in .NET
- Pattern Matching with Discriminated Unions in .NET
- Discriminated Unions in .NET: Modeling States and Variants
- Discriminated Unions in .NET: Integration with Frameworks and Libraries
Migrations
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Thinktecture.Runtime.Extensions.SourceGenerator (>= 10.1.0-beta01)
-
net9.0
- Thinktecture.Runtime.Extensions.SourceGenerator (>= 10.1.0-beta01)
NuGet packages (13)
Showing the top 5 NuGet packages that depend on Thinktecture.Runtime.Extensions:
| Package | Downloads |
|---|---|
|
Thinktecture.Runtime.Extensions.Json
Adds JSON support to components from Thinktecture.Runtime.Extensions when using System.Text.Json. |
|
|
Thinktecture.Runtime.Extensions.AspNetCore
Adds ASP.NET Core support to components from Thinktecture.Runtime.Extensions. |
|
|
Thinktecture.Runtime.Extensions.EntityFrameworkCore
Extends Entity Framework Core to support some components from Thinktecture.Runtime.Extensions. |
|
|
Thinktecture.Runtime.Extensions.EntityFrameworkCore8
Extends Entity Framework Core to support some components from Thinktecture.Runtime.Extensions. |
|
|
Thinktecture.Runtime.Extensions.Newtonsoft.Json
Adds better JSON support to components from Thinktecture.Runtime.Extensions when using Newtonsoft.Json. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.1.0-beta02 | 0 | 3/2/2026 |
| 10.1.0-beta01 | 0 | 3/1/2026 |
| 10.0.0 | 3,402 | 2/12/2026 |
| 10.0.0-beta04 | 723 | 2/9/2026 |
| 10.0.0-beta03 | 3,839 | 1/13/2026 |
| 10.0.0-beta02 | 6,395 | 11/30/2025 |
| 10.0.0-beta01 | 1,027 | 11/19/2025 |
| 9.7.1 | 7,146 | 11/19/2025 |
| 9.7.0 | 1,516 | 11/12/2025 |
| 9.7.0-rc1 | 443 | 11/11/2025 |
| 9.7.0-beta08 | 363 | 11/9/2025 |
| 9.7.0-beta07 | 342 | 10/27/2025 |
| 9.7.0-beta06 | 337 | 10/27/2025 |
| 9.7.0-beta05 | 342 | 10/27/2025 |
| 9.7.0-beta04 | 340 | 10/21/2025 |
| 9.7.0-beta03 | 329 | 10/19/2025 |
| 9.6.6 | 1,112 | 11/8/2025 |
| 9.6.5 | 1,054 | 11/3/2025 |
| 9.6.4 | 1,659 | 10/21/2025 |
| 9.6.3 | 494 | 10/19/2025 |