Home - PawelGerr/Thinktecture.Runtime.Extensions GitHub Wiki
This library uses Roslyn Source Generators, Analyzers, CodeFixes, and Refactorings to provide Smart Enums (type-safe alternatives to enum), Value Objects (immutable domain primitives with built-in validation), and Discriminated Unions (type-safe "one of" types).
Core Concepts
-
Smart Enums -- Type-safe enumerations with behavior, supporting keyed (with an underlying value) and keyless variants.
- Customization -- Attribute settings, equality, comparison, parsable interfaces, and more
- Framework Integration -- System.Text.Json, EF Core, ASP.NET Core, MessagePack, Newtonsoft.Json
- Performance -- Span-based JSON, zero-allocation parsing, benchmarks
-
Value Objects -- Immutable domain primitives (simple single-value or complex multi-property) with built-in validation and factory methods.
- Customization -- Attribute settings, equality comparers, factory methods, operators
- Framework Integration -- System.Text.Json, EF Core, ASP.NET Core, MessagePack, Newtonsoft.Json
-
Discriminated Unions -- Type-safe unions including ad-hoc unions (
Union<T1, T2, ...>) and regular inheritance-based unions, withSwitch/Mappattern matching.- Customization -- Attribute settings, backing fields, stateless types, constructors
- Framework Integration -- System.Text.Json, EF Core, MessagePack, Newtonsoft.Json
Supporting Topics
- Object Factories -- Custom creation logic via
[ObjectFactory<T>]for advanced parsing and deserialization scenarios - Analyzer Diagnostics -- Reference for all
TTRESGdiagnostic rules - Source Generator Configuration -- MSBuild properties for controlling generator behavior
Convenience Methods and Classes
- Empty (collections/actions/disposables)
- ToReadOnlyCollection
- TrimOrNullify (strings)
- SingleItem (collections)
Requirements
- C# 11 (or higher) for generated code
- SDK 8.0.416 (or higher) for building projects