{"id":24129389,"url":"https://github.com/pawelgerr/thinktecture.runtime.extensions","last_synced_at":"2026-03-02T00:02:11.066Z","repository":{"id":56455857,"uuid":"121141262","full_name":"PawelGerr/Thinktecture.Runtime.Extensions","owner":"PawelGerr","description":"Provides an easy way to implement Smart Enums and Value Objects","archived":false,"fork":false,"pushed_at":"2024-04-14T09:40:28.000Z","size":2716,"stargazers_count":46,"open_issues_count":1,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-14T09:53:21.862Z","etag":null,"topics":["csharp","dotnet","dotnet-core","roslyn-generator","smart-enum","smart-enums","source-generator","value-object","value-objects"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PawelGerr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-02-11T16:13:46.000Z","updated_at":"2024-04-18T19:39:53.524Z","dependencies_parsed_at":"2023-11-28T08:26:12.785Z","dependency_job_id":"1773bf86-6f18-420d-960d-e8e718c4f46b","html_url":"https://github.com/PawelGerr/Thinktecture.Runtime.Extensions","commit_stats":null,"previous_names":[],"tags_count":81,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelGerr%2FThinktecture.Runtime.Extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelGerr%2FThinktecture.Runtime.Extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelGerr%2FThinktecture.Runtime.Extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelGerr%2FThinktecture.Runtime.Extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PawelGerr","download_url":"https://codeload.github.com/PawelGerr/Thinktecture.Runtime.Extensions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233526149,"owners_count":18689438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","dotnet-core","roslyn-generator","smart-enum","smart-enums","source-generator","value-object","value-objects"],"created_at":"2025-01-11T19:31:52.437Z","updated_at":"2026-03-02T00:02:11.047Z","avatar_url":"https://github.com/PawelGerr.png","language":"C#","readme":"![Build](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/workflows/CI/badge.svg) ![TestResults](https://gist.githubusercontent.com/PawelGerr/043909cfb348b36187d02222da1f372e/raw/badge.svg) ![NuGet Downloads](https://img.shields.io/nuget/dt/Thinktecture.Runtime.Extensions)\n\n# Thinktecture.Runtime.Extensions\n\nA .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.\n\n## Quick Start\n\n```\nInstall-Package Thinktecture.Runtime.Extensions\n```\n\n## Smart Enums\n\nType-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.\n\n```csharp\n[SmartEnum\u003cstring\u003e]\npublic partial class ShippingMethod\n{\n   public static readonly ShippingMethod Standard = new(\"STANDARD\", basePrice: 5.99m, estimatedDays: 5);\n   public static readonly ShippingMethod Express = new(\"EXPRESS\", basePrice: 15.99m, estimatedDays: 2);\n\n   public decimal CalculatePrice(decimal weight) =\u003e _basePrice + weight;\n}\n```\n\n[Full documentation](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Smart-Enums) -- customization, real-world examples, performance tips, framework integration.\n\n## Value Objects\n\nImmutable 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.\n\n**Simple value object**\n\n```csharp\n[ValueObject\u003cdecimal\u003e]\npublic partial struct Amount\n{\n    static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref decimal value)\n    {\n        if (value \u003c 0)\n            validationError = new ValidationError(\"Amount cannot be negative\");\n    }\n}\n```\n\n**Complex value object**\n\n```csharp\n[ComplexValueObject]\npublic partial class Boundary\n{\n    public decimal Lower { get; }\n    public decimal Upper { get; }\n\n    static partial void ValidateFactoryArguments(ref ValidationError? validationError, ref decimal lower, ref decimal upper)\n    {\n        if (lower \u003e upper)\n            validationError = new ValidationError(\"Lower must be less than or equal to Upper\");\n    }\n}\n```\n\n[Full documentation](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects) -- simple \u0026 complex value objects, customization, framework integration.\n\n## Discriminated Unions\n\nModel \"one of\" types with full type safety. Choose ad-hoc unions for quick combinations (`Union\u003cT1, T2\u003e`) or regular unions (`Union`) for rich domain modeling with exhaustive `Switch`/`Map`.\n\n**Ad-hoc union**\n\n```csharp\n[Union\u003cstring, int\u003e]\npublic partial struct TextOrNumber;\n```\n\n**Regular union**\n\n```csharp\n[Union]\npublic partial record Result\u003cT\u003e\n{\n    public sealed record Success(T Value) : Result\u003cT\u003e;\n    public sealed record Failure(string Error) : Result\u003cT\u003e;\n}\n```\n\n[Full documentation](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Discriminated-Unions) -- ad-hoc unions, regular unions, customization, framework integration.\n\n## Framework Integration\n\nAll generated types integrate with the .NET ecosystem out of the box:\n\n- **System.Text.Json** -- zero-allocation span-based serialization on .NET 9+\n- **Entity Framework Core** -- value converters for EF Core 8, 9, and 10\n- **ASP.NET Core** -- model binding and Minimal API parameter binding via `IParsable\u003cT\u003e`\n- **MessagePack** -- binary serialization support\n- **Newtonsoft.Json** -- `JsonConverter` support\n- **Swashbuckle / OpenAPI** -- schema and operation filters\n\n## Packages\n\n| Package | NuGet |\n|---------|-------|\n| Thinktecture.Runtime.Extensions | [![NuGet](https://img.shields.io/nuget/v/Thinktecture.Runtime.Extensions.svg?maxAge=60)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions/) |\n| Thinktecture.Runtime.Extensions.Json | [![NuGet](https://img.shields.io/nuget/v/Thinktecture.Runtime.Extensions.Json.svg?maxAge=60)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.Json/) |\n| Thinktecture.Runtime.Extensions.Newtonsoft.Json | [![NuGet](https://img.shields.io/nuget/v/Thinktecture.Runtime.Extensions.Newtonsoft.Json.svg?maxAge=60)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.Newtonsoft.Json/) |\n| Thinktecture.Runtime.Extensions.MessagePack | [![NuGet](https://img.shields.io/nuget/v/Thinktecture.Runtime.Extensions.MessagePack.svg?maxAge=60)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.MessagePack/) |\n| Thinktecture.Runtime.Extensions.EntityFrameworkCore8 | [![NuGet](https://img.shields.io/nuget/v/Thinktecture.Runtime.Extensions.EntityFrameworkCore8.svg?maxAge=60)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.EntityFrameworkCore8/) |\n| Thinktecture.Runtime.Extensions.EntityFrameworkCore9 | [![NuGet](https://img.shields.io/nuget/v/Thinktecture.Runtime.Extensions.EntityFrameworkCore9.svg?maxAge=60)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.EntityFrameworkCore9/) |\n| Thinktecture.Runtime.Extensions.EntityFrameworkCore10 | [![NuGet](https://img.shields.io/nuget/v/Thinktecture.Runtime.Extensions.EntityFrameworkCore10.svg?maxAge=60)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.EntityFrameworkCore10/) |\n| Thinktecture.Runtime.Extensions.AspNetCore | [![NuGet](https://img.shields.io/nuget/v/Thinktecture.Runtime.Extensions.AspNetCore.svg?maxAge=60)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.AspNetCore/) |\n| Thinktecture.Runtime.Extensions.Swashbuckle | [![NuGet](https://img.shields.io/nuget/v/Thinktecture.Runtime.Extensions.Swashbuckle.svg?maxAge=60)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.Swashbuckle/) |\n\n## Requirements\n\n- C# 11 (or higher) for generated code\n- SDK 8.0.416 (or higher) for building projects\n\n## Documentation\n\n- [Smart Enums](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Smart-Enums) -- overview, real-world examples, design patterns\n  - [Customization](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Smart-Enums-Customization) -- attribute settings, equality, comparison, parsable interfaces\n  - [Framework Integration](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Smart-Enums-Framework-Integration) -- JSON, EF Core, ASP.NET Core, MessagePack\n  - [Performance](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Smart-Enums-Performance) -- span-based JSON, zero-allocation parsing, benchmarks\n- [Value Objects](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects) -- simple \u0026 complex value objects, validation\n  - [Customization](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects-Customization) -- attribute settings, equality comparers, factory methods, operators\n  - [Framework Integration](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Value-Objects-Framework-Integration) -- JSON, EF Core, ASP.NET Core, MessagePack\n- [Discriminated Unions](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Discriminated-Unions) -- ad-hoc and regular unions, pattern matching\n  - [Customization](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Discriminated-Unions-Customization) -- backing fields, stateless types, constructors\n  - [Framework Integration](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Discriminated-Unions-Framework-Integration) -- JSON, EF Core, MessagePack\n- [Object Factories](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Object-Factories) -- custom creation logic for advanced parsing and deserialization\n- [Analyzer Diagnostics](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Analyzer-Diagnostics) -- reference for all `TTRESG` diagnostic rules\n- [Source Generator Configuration](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Source-Generator-Configuration) -- MSBuild properties for controlling generator behavior\n\n## Articles\n\n**Smart Enums**:\n- [Smart Enums: Beyond Traditional Enumerations in .NET](https://www.thinktecture.com/en/net/smart-enums-beyond-traditional-enumerations-in-dotnet/)\n- [Smart Enums: Adding Domain Logic to Enumerations in .NET](https://www.thinktecture.com/en/net/smart-enums-adding-domain-logic-to-enumerations-in-dotnet/)\n- [Smart Enums in .NET: Integration with Frameworks and Libraries](https://www.thinktecture.com/en/net/smart-enums-in-net-integration-with-frameworks-and-libraries/)\n\n**Value Objects**:\n- [Value Objects: Solving Primitive Obsession in .NET](https://www.thinktecture.com/en/net/value-objects-solving-primitive-obsession-in-net/)\n- [Handling Complexity: Introducing Complex Value Objects in .NET](https://www.thinktecture.com/en/net/handling-complexity-introducing-complex-value-objects-in-dotnet/)\n- [Value Objects in .NET: Integration with Frameworks and Libraries](https://www.thinktecture.com/en/net/value-objects-in-net-integration-with-frameworks-and-libraries/)\n- [Value Objects in .NET: Enhancing Business Semantics](https://www.thinktecture.com/en/net/value-objects-in-dotnet-enhancing-business-semantics/)\n- [Advanced Value Object Patterns in .NET](https://www.thinktecture.com/en/net/advanced-value-object-patterns-in-net/)\n\n**Discriminated Unions**:\n- [Discriminated Unions: Representation of Alternative Types in .NET](https://www.thinktecture.com/en/net/discriminated-unions-representation-of-alternative-types-in-dotnet/)\n- [Pattern Matching with Discriminated Unions in .NET](https://www.thinktecture.com/en/net/pattern-matching-with-discriminated-unions-in-net/)\n- [Discriminated Unions in .NET: Modeling States and Variants](https://www.thinktecture.com/en/net/discriminated-unions-in-net-modeling-states-and-variants/)\n- [Discriminated Unions in .NET: Integration with Frameworks and Libraries](https://www.thinktecture.com/en/net/discriminated-unions-in-net-integration-with-frameworks-and-libraries/)\n\n## Migrations\n\n- [Migration from v9 to v10](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Migration-from-v9-to-v10)\n- [Migration from v8 to v9](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Migration-from-v8-to-v9)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawelgerr%2Fthinktecture.runtime.extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpawelgerr%2Fthinktecture.runtime.extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawelgerr%2Fthinktecture.runtime.extensions/lists"}