{"id":48433871,"url":"https://github.com/linkdotnet/enumeration","last_synced_at":"2026-04-12T11:01:14.602Z","repository":{"id":349390422,"uuid":"1202143785","full_name":"linkdotnet/Enumeration","owner":"linkdotnet","description":"A source code generated string enum with exhaustion checks!","archived":false,"fork":false,"pushed_at":"2026-04-10T09:01:07.000Z","size":104,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-10T09:37:35.820Z","etag":null,"topics":[],"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/linkdotnet.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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}},"created_at":"2026-04-05T16:51:48.000Z","updated_at":"2026-04-10T09:01:12.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/linkdotnet/Enumeration","commit_stats":null,"previous_names":["linkdotnet/enumeration"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/linkdotnet/Enumeration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FEnumeration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FEnumeration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FEnumeration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FEnumeration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkdotnet","download_url":"https://codeload.github.com/linkdotnet/Enumeration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FEnumeration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31676210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T08:18:19.405Z","status":"ssl_error","status_checked_at":"2026-04-11T08:17:08.892Z","response_time":54,"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":[],"created_at":"2026-04-06T12:02:01.522Z","updated_at":"2026-04-11T10:01:53.804Z","avatar_url":"https://github.com/linkdotnet.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enumeration\n\n[![.NET](https://github.com/linkdotnet/Enumeration/actions/workflows/dotnet.yml/badge.svg)](https://github.com/linkdotnet/Enumeration/actions/workflows/dotnet.yml)\n[![Nuget](https://img.shields.io/nuget/dt/LinkDotNet.Enumeration)](https://www.nuget.org/packages/LinkDotNet.Enumeration/)\n[![GitHub tag](https://img.shields.io/github/v/tag/linkdotnet/Enumeration?include_prereleases\u0026logo=github\u0026style=flat-square)](https://github.com/linkdotnet/Enumeration/releases)\n\nSource code generated string Enumeration with completeness!\n\n## What is in the box?\n\nThis source code generator let's you easily create string based enumerations with a lot of features.\n\n```csharp\n[Enumeration(\"Red\", \"Green\", \"Blue\")]\npublic sealed partial record Color;\n```\n\nThat's all you need to do to create a string based enumeration. You can either use it like this:\n\n```csharp\nvar color = Color.Red;\n\n// Create it by a string key:\nvar color = Color.Create(\"Red\");\n```\n\n## Exhaustiveness\n\nThe great benefit of the library is that you have support for exhaustiveness:\n\n\n```csharp\n\nvar color = Color.Create(\"Red\");\n\ncolor.Match(\n    red =\u003e Console.WriteLine(\"It's red!\"),\n    green =\u003e Console.WriteLine(\"It's green!\"),\n    blue =\u003e Console.WriteLine(\"It's blue!\")\n);\n```\n\nOr return a value:\n\n```csharp\nvar color = Color.Create(\"Red\");\n\nvar colorCode = color.Match(\n    red =\u003e \"#FF0000\",\n    green =\u003e \"#00FF00\",\n    blue =\u003e \"#0000FF\"\n);\n```\n\n## More features!\n\n### Controlling field names\n\nThe `Enumeration` attribute accepts an optional first argument of type `Casing` to control how the static member names are derived from the string values. By default, the library uses `PascalCase` to convert string values into member names. If you want to preserve the original casing of the string values, you can set the `Casing` to `Preserve`.\n\n```csharp\n[Enumeration(Casing.Preserve, \"red\", \"green\", \"blue\")]\npublic sealed partial class Color;\n```\n\nGenerates:\n\n```csharp\npublic sealed partial class Color\n{\n    public static readonly Color red = new(\"red\");\n    public static readonly Color green = new(\"green\");\n    public static readonly Color blue = new(\"blue\");\n    // ...\n```\n\nThe default is `PascalCase` to feel \"natural\" to C# developers.\n\n### Creating from a string key\n\nTwo methods are exposed `Create` and `TryCreate` to create an instance of the enumeration from a string key. The `Create` method will throw an `ArgumentException` if the key is not valid, while the `TryCreate` method will return a boolean indicating whether the creation was successful and output the created value through an out parameter.\n\n```csharp\nvar color = Color.Create(\"Red\"); // Throws if \"Red\" is not a valid key\n\nif (Color.TryCreate(\"Red\", out var color))\n{\n    // Use color\n}\nelse\n{\n    // Handle invalid key\n}\n```\n\n### Parsing (IParsable)\n\nThe generated types implement `IParsable\u003cT\u003e` and `ISpanParsable\u003cT\u003e`, making them compatible with modern .NET features like Minimal APIs and Model Binding.\n\n```csharp\nif (Color.TryParse(\"Red\", null, out var color))\n{\n    // Use color\n}\n```\n\n### Implicit/Explicit Conversions\n\nInstances of the generated enumeration can be implicitly converted to strings (returns the `Key` property), and strings can be explicitly converted back to the enumeration type (calls `Create`).\n\n```csharp\nstring colorKey = Color.Red; // Implicit conversion\nvar color = (Color)\"Green\"; // Explicit conversion\n```\n\n### Equality and Comparison\n\nRecords implement value-based equality by default. For classes, `IEquatable\u003cT\u003e` is automatically implemented, comparing the `Key` property.\n\n```csharp\nvar isRed = Color.Red == \"Red\"; // String comparison\nvar areEqual = Color.Red.Equals(Color.Create(\"Red\")); // Value equality\n```\n\n### Getting all values\n\nCalling `All` will return a collection of all possible values. This is implemented using a `FrozenSet` to ensure immutability and thread-safety.\n\n## `JsonConverter` Generation\n\nThe library allows via the `GenerateJsonConverter` property on the `Enumeration` attribute to generate a `JsonConverter` for the enumeration type. This converter will handle serialization and deserialization of the enumeration values as their string keys.\n\n```csharp\n[Enumeration(\"Red\", \"Green\", \"Blue\", GenerateJsonConverter = true)]\npublic sealed partial record Color;\n```\n\nThis will generate a `JsonConverter` that can be used with `System.Text.Json` to serialize and deserialize `Color` instances as their string keys. The generated converter is called `{TypeName}JsonConverter`.\n\n### Limitations\n\n* Your code should run at least `net8.0` or later, as the library uses things like `FrozenSet`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdotnet%2Fenumeration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkdotnet%2Fenumeration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdotnet%2Fenumeration/lists"}