GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - PawelGerr/Thinktecture.Runtime.Extensions: Provides an easy way to implement Smart Enums, Value Objects and Discriminated Unions in .NET

BranchesTags
Open more actions menu

Latest commit

 

History

954 Commits
954 Commits

Folders and files

NameName
Last commit message
Last commit date
.claude
.claude
 
 
.github
.github
 
 
.serena
.serena
 
 
agent-skills @ dd99514
agent-skills @ dd99514
 
 
docs @ 2405ed8
docs @ 2405ed8
 
 
samples
samples
 
 
skills/thinktecture-runtime-extensions
skills/thinktecture-runtime-extensions
 
 
src
src
 
 
test
test
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
Directory.Build.props
Directory.Build.props
 
 
Directory.Packages.props
Directory.Packages.props
 
 
LICENSE.md
LICENSE.md
 
 
NuGet.config
NuGet.config
 
 
README.md
README.md
 
 
Thinktecture.Runtime.Extensions.sln.DotSettings
Thinktecture.Runtime.Extensions.sln.DotSettings
 
 
Thinktecture.Runtime.Extensions.slnx
Thinktecture.Runtime.Extensions.slnx
 
 
context7.json
context7.json
 
 
global.json
global.json
 
 
icon.png
icon.png
 
 

Repository files navigation

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
  • Serilog -- destructuring policy for compact, key-based structured logging

AI Coding Assistants

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

Agent skill -- a curated guidance package maintained in the repository PawelGerr/agent-skills 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/agent-skills --skill 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. Claude Code users can install it as a plugin instead: /plugin marketplace add PawelGerr/agent-skills followed by /plugin install thinktecture-runtime-extensions@pawelgerr.

If you installed the skill from PawelGerr/Thinktecture.Runtime.Extensions, reinstall it from PawelGerr/agent-skills with the command above. This repository keeps only a redirect stub.

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
Thinktecture.Runtime.Extensions.Serilog NuGet

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 TTRESG diagnostic rules
  • Source Generator Configuration -- MSBuild properties for controlling generator behavior
  • AI Coding Assistants -- the agent skill (npx skills or Claude Code plugin) and Context7 (MCP) support for Claude Code, Cursor, and other AI coding agents

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

  • Migration from v9 to v10
  • Migration from v8 to v9

About

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

Topics

csharpdiscriminated-unionsdotnetdotnet-coresmart-enumssource-generatorsvalue-objects

Resources

Readme
BSD-3-Clause license
Activity

Stars

94 stars

Watchers

4 watching

Forks

5 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.