{"id":47748908,"url":"https://github.com/layeredcraft/optimized-enums","last_synced_at":"2026-04-06T05:00:43.216Z","repository":{"id":348088888,"uuid":"1196254668","full_name":"LayeredCraft/optimized-enums","owner":"LayeredCraft","description":"High-performance typed enum pattern for .NET using source generation. No reflection, AOT-friendly, and designed for modern workloads like Blazor WASM and AWS Lambda.","archived":false,"fork":false,"pushed_at":"2026-04-01T11:05:03.000Z","size":176,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-04T03:23:37.457Z","etag":null,"topics":["aws","dotnet","layeredcraft","open-source","serverless"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LayeredCraft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"ncipollina","custom":["https://github.com/sponsors/ncipollina"]}},"created_at":"2026-03-30T14:18:07.000Z","updated_at":"2026-04-01T10:59:34.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/LayeredCraft/optimized-enums","commit_stats":null,"previous_names":["layeredcraft/optimized-enums"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/LayeredCraft/optimized-enums","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LayeredCraft%2Foptimized-enums","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LayeredCraft%2Foptimized-enums/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LayeredCraft%2Foptimized-enums/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LayeredCraft%2Foptimized-enums/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LayeredCraft","download_url":"https://codeload.github.com/LayeredCraft/optimized-enums/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LayeredCraft%2Foptimized-enums/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31423887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T02:22:46.605Z","status":"ssl_error","status_checked_at":"2026-04-05T02:22:33.263Z","response_time":75,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["aws","dotnet","layeredcraft","open-source","serverless"],"created_at":"2026-04-03T02:26:48.380Z","updated_at":"2026-04-06T05:00:43.198Z","avatar_url":"https://github.com/LayeredCraft.png","language":"C#","readme":"# LayeredCraft.OptimizedEnums\n\n**LayeredCraft.OptimizedEnums** is a modular C# .NET library providing high-performance, AOT-safe smart enum patterns using source generation. Inherit from a base class and the generator produces O(1) lookup tables, collection properties, and factory methods — all at compile time with zero reflection at runtime.\n\n## Key Features\n\n- **Zero reflection** — all lookup tables are source-generated at compile time\n- **AOT / trimming friendly** — compatible with NativeAOT, ReadyToRun, and Blazor WASM\n- **O(1) lookups** — `FromName`, `FromValue`, `ContainsName`, `ContainsValue`\n- **Compile-time validation** — errors for missing `partial`, duplicate values/names\n- **No allocations per call** — all collections are statically cached\n- **Inheritance-based triggering** — no attribute required, just inherit and go\n\n## 📦 Packages\n\n| Package | NuGet | Downloads |\n|---------|-------|-----------|\n| **LayeredCraft.OptimizedEnums** | [![NuGet](https://img.shields.io/nuget/v/LayeredCraft.OptimizedEnums.svg)](https://www.nuget.org/packages/LayeredCraft.OptimizedEnums) | [![Downloads](https://img.shields.io/nuget/dt/LayeredCraft.OptimizedEnums.svg)](https://www.nuget.org/packages/LayeredCraft.OptimizedEnums/) |\n| **LayeredCraft.OptimizedEnums.SystemTextJson** | [![NuGet](https://img.shields.io/nuget/v/LayeredCraft.OptimizedEnums.SystemTextJson.svg)](https://www.nuget.org/packages/LayeredCraft.OptimizedEnums.SystemTextJson) | [![Downloads](https://img.shields.io/nuget/dt/LayeredCraft.OptimizedEnums.SystemTextJson.svg)](https://www.nuget.org/packages/LayeredCraft.OptimizedEnums.SystemTextJson/) |\n| **LayeredCraft.OptimizedEnums.EFCore** | _coming soon_ | |\n| **LayeredCraft.OptimizedEnums.Dapper** | _coming soon_ | |\n| **LayeredCraft.OptimizedEnums.AutoFixture** | _coming soon_ | |\n\n[![Build Status](https://github.com/LayeredCraft/optimized-enums/actions/workflows/build.yaml/badge.svg)](https://github.com/LayeredCraft/optimized-enums/actions/workflows/build.yaml)\n\n## Usage\n\n```csharp\npublic sealed partial class OrderStatus : OptimizedEnum\u003cOrderStatus, int\u003e\n{\n    public static readonly OrderStatus Pending = new(1, nameof(Pending));\n    public static readonly OrderStatus Paid    = new(2, nameof(Paid));\n    public static readonly OrderStatus Shipped = new(3, nameof(Shipped));\n\n    private OrderStatus(int value, string name) : base(value, name) { }\n}\n```\n\nOr use the `int`-defaulting convenience base class:\n\n```csharp\npublic sealed partial class Priority : OptimizedEnum\u003cPriority\u003e\n{\n    public static readonly Priority Low    = new(1, nameof(Low));\n    public static readonly Priority Medium = new(2, nameof(Medium));\n    public static readonly Priority High   = new(3, nameof(High));\n\n    private Priority(int value, string name) : base(value, name) { }\n}\n```\n\nThe source generator produces:\n\n```csharp\n// Lookup\nvar status = OrderStatus.FromName(\"Paid\");       // OrderStatus.Paid\nvar status = OrderStatus.FromValue(3);           // OrderStatus.Shipped\n\n// Try-style\nOrderStatus.TryFromName(\"Paid\", out var result);\nOrderStatus.TryFromValue(3, out var result);\n\n// Membership\nOrderStatus.ContainsName(\"Paid\");   // true\nOrderStatus.ContainsValue(99);      // false\n\n// Enumeration\nIReadOnlyList\u003cOrderStatus\u003e all    = OrderStatus.All;\nIReadOnlyList\u003cstring\u003e      names  = OrderStatus.Names;\nIReadOnlyList\u003cint\u003e         values = OrderStatus.Values;\nint count = OrderStatus.Count;      // compile-time constant\n```\n\n## Performance\n\nBenchmarks run on Apple M3 Max, .NET 9.0.8, BenchmarkDotNet v0.14.0.\n\n| Method        | Mean     | Allocated |\n|-------------- |---------:|----------:|\n| FromName      | 5.48 ns  | 0 B       |\n| TryFromName   | 4.53 ns  | 0 B       |\n| FromValue     | 2.18 ns  | 0 B       |\n| TryFromValue  | 1.21 ns  | 0 B       |\n| ContainsName  | 4.54 ns  | 0 B       |\n| ContainsValue | 1.18 ns  | 0 B       |\n| GetAll        | 0.76 ns  | 0 B       |\n| GetCount      | ~0 ns    | 0 B       |\n\nAll lookups are O(1) via statically-cached dictionaries. `Count` is a compile-time constant.\n\n## JSON Serialization\n\nAdd `LayeredCraft.OptimizedEnums.SystemTextJson` for source-generated, zero-reflection `JsonConverter` support. One package is all you need — it pulls in the core package automatically:\n\n```bash\ndotnet add package LayeredCraft.OptimizedEnums.SystemTextJson\n```\n\nDecorate your class with `[OptimizedEnumJsonConverter]` and the generator emits a concrete, AOT-safe converter and wires it up via `[JsonConverter]`:\n\n```csharp\nusing LayeredCraft.OptimizedEnums;\nusing LayeredCraft.OptimizedEnums.SystemTextJson;\n\n[OptimizedEnumJsonConverter(OptimizedEnumJsonConverterType.ByName)]\npublic sealed partial class OrderStatus : OptimizedEnum\u003cOrderStatus, int\u003e\n{\n    public static readonly OrderStatus Pending = new(1, nameof(Pending));\n    public static readonly OrderStatus Paid    = new(2, nameof(Paid));\n    public static readonly OrderStatus Shipped = new(3, nameof(Shipped));\n\n    private OrderStatus(int value, string name) : base(value, name) { }\n}\n```\n\n```json\n{ \"status\": \"Pending\" }\n```\n\nTwo strategies are available: `ByName` (serializes as the member name string) and `ByValue` (serializes as the underlying value). See the [JSON Serialization docs](https://layeredcraft.github.io/optimized-enums/usage/json-serialization/) for full details.\n\n## Installation\n\n```bash\ndotnet add package LayeredCraft.OptimizedEnums\n```\n\nSupports **.NET 8.0**, **.NET 9.0**, **.NET 10.0**.\n\n## Documentation\n\nFull documentation is available at the [LayeredCraft.OptimizedEnums docs site](https://layeredcraft.github.io/optimized-enums).\n\n## License\n\nMIT\n","funding_links":["https://github.com/sponsors/ncipollina"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flayeredcraft%2Foptimized-enums","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flayeredcraft%2Foptimized-enums","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flayeredcraft%2Foptimized-enums/lists"}