Extends Entity Framework Core to support some components from Thinktecture.Runtime.Extensions.
$ dotnet add package Thinktecture.Runtime.Extensions.EntityFrameworkCore9
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.
Install-Package Thinktecture.Runtime.Extensions
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.
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.
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.
All generated types integrate with the .NET ecosystem out of the box:
IParsable<T>JsonConverter supportTTRESG diagnostic rulesSmart Enums:
Value Objects:
Discriminated Unions: