{"id":20545859,"url":"https://github.com/xin9le/fastenum","last_synced_at":"2025-05-14T11:10:38.054Z","repository":{"id":39999996,"uuid":"206027124","full_name":"xin9le/FastEnum","owner":"xin9le","description":"The world fastest enum utilities for C#/.NET","archived":false,"fork":false,"pushed_at":"2025-04-07T16:29:34.000Z","size":909,"stargazers_count":436,"open_issues_count":4,"forks_count":28,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-29T18:50:48.290Z","etag":null,"topics":["csharp","enum","high-performance","netstandard","utility"],"latest_commit_sha":null,"homepage":"","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/xin9le.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2019-09-03T08:26:05.000Z","updated_at":"2025-04-27T20:50:32.000Z","dependencies_parsed_at":"2024-08-27T13:24:45.790Z","dependency_job_id":"980dedc9-d05d-4811-ab5f-bfa4a1b55d92","html_url":"https://github.com/xin9le/FastEnum","commit_stats":{"total_commits":591,"total_committers":3,"mean_commits":197.0,"dds":"0.0033840947546531774","last_synced_commit":"acb66b1cf6db1bd6e59f847774fe830bb8d47f45"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xin9le%2FFastEnum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xin9le%2FFastEnum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xin9le%2FFastEnum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xin9le%2FFastEnum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xin9le","download_url":"https://codeload.github.com/xin9le/FastEnum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129489,"owners_count":22019628,"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","enum","high-performance","netstandard","utility"],"created_at":"2024-11-16T01:53:36.143Z","updated_at":"2025-05-14T11:10:37.987Z","avatar_url":"https://github.com/xin9le.png","language":"C#","readme":"# FastEnum\nFastEnum is **extremely fast** enum utilities for C#/.NET. It's much faster than .NET. Provided methods are all achieved **zero allocation** and are designed easy to use like `System.Enum`. This library is quite useful to significantly improve your performance because enum is really popular feature.\n\n[![Releases](https://img.shields.io/github/release/xin9le/FastEnum.svg)](https://github.com/xin9le/FastEnum/releases)\n[![Nuget packages](https://img.shields.io/nuget/v/FastEnum.svg)](https://www.nuget.org/packages/FastEnum/)\n[![GitHub license](https://img.shields.io/github/license/xin9le/FastEnum)](https://github.com/xin9le/FastEnum/blob/main/LICENSE)\n[![Build and Test](https://github.com/xin9le/FastEnum/actions/workflows/test.yml/badge.svg)](https://github.com/xin9le/FastEnum/actions/workflows/test.yml)\n\n\n\n# Performance\n![Benchmark](https://github.com/user-attachments/assets/81755afc-30ad-4e20-9737-fa3031ef52aa)\n\n\n``` ini\nBenchmarkDotNet v0.14.0, Windows 11 (10.0.22621.4037/22H2/2022Update/SunValley2)\n13th Gen Intel Core i7-1360P, 1 CPU, 16 logical and 12 physical cores\n.NET SDK 8.0.400\n  [Host]     : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2\n  Job-CYQAVK : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2\n```\n\n\n\n# Support Platform\n- .NET 8.0+\n\n\u003e [!Important]\n\u003e For those who wish to use this on older platforms, please use v1.8.0. It supports follows.\n\u003e - .NET Framework 4.6.1+\n\u003e - .NET Standard 2.0+\n\u003e - .NET 5+\n\n\n\n# How to use\nThis library super easy to use like `System.Enum` that is standard of .NET. Look below:\n\n```cs\n//--- FastEnum\nvar values = FastEnum.GetValues\u003cFruits\u003e();\nvar names = FastEnum.GetNames\u003cFruits\u003e();\nvar name = FastEnum.GetName(Fruits.Apple);\nvar toString = Fruits.Apple.FastToString();\nvar defined = FastEnum.IsDefined(Fruits.Apple);\nvar parse = FastEnum.Parse\u003cFruits\u003e(\"Apple\");\nvar tryParse = FastEnum.TryParse\u003cFruits\u003e(\"Apple\", out var value);\n```\n\n```cs\n//--- .NET\nvar values = Enum.GetValues\u003cFruits\u003e();\nvar names = Enum.GetNames\u003cFruits\u003e();\nvar name = Enum.GetName(Fruits.Apple);\nvar toString = Fruits.Apple.ToString();\nvar defined = Enum.IsDefined(Fruits.Apple);\nvar parse = Enum.Parse\u003cFruits\u003e(\"Apple\");\nvar tryParse = Enum.TryParse\u003cFruits\u003e(\"Apple\", out var value);\n```\n\nAs you can see, the replacement from `System.Enum` is very easy. You never confuse.\n\n\n\n# Source code generation\nFastEnum is fundamentally implemented based on caching enum metadata upon its initial invocation. This approach alone achieves speeds that significantly surpass those of standard .NET, making it the optimal choice for the majority of users. Nevertheless, we acknowledge the existence of mission-critical scenarios where the ultimate pursuit of speed is paramount. To address such cases, we have introduced an API in v2 that leverages source code generation to achieve even higher performance.\n\n```cs\n[FastEnum\u003cHttpStatusCode\u003e]  // Annotate target enum type\npartial class HttpStatusCodeBooster  // Placeholder for source code generation\n{ }\n\nvar x1 = FastEnum.ToString\u003cHttpStatusCode, HttpStatusCodeBooster\u003e(HttpStatusCode.OK);\nvar x2 = FastEnum.IsDefined\u003cHttpStatusCode, HttpStatusCodeBooster\u003e(HttpStatusCode.OK);\nvar x3 = FastEnum.Parse\u003cHttpStatusCode, HttpStatusCodeBooster\u003e(\"OK\");\nvar x4 = FastEnum.TryParse\u003cHttpStatusCode, HttpStatusCodeBooster\u003e(\"OK\", out var value);\n```\n\n\n\n# More features\nThere are some functions that are often used for enum, and you can be used more conveniently by including them together.\n\n\n## 1. Gets pairwised member information\nSometimes you want name / value pair of enum. `Member\u003cTEnum\u003e` can be used under such cases. Of course supports [deconstruction](https://docs.microsoft.com/en-us/dotnet/csharp/deconstruct) feature. `FieldInfo` is also included, so please use it for reflection code.\n\n\n```cs\nclass Member\u003cTEnum\u003e\n{\n    public TEnum Value { get; }\n    public string Name { get; }\n    public FieldInfo FieldInfo { get; }\n    // etc...\n}\n\nvar member = Fruits.Apple.ToMember()!;\nvar (name, value) = member;  // Supports deconstruction\n```\n\n\n## 2. Gets `EnumMemberAttribute.Value`\nI often see the developer using `EnumMemberAttribute` as an alias for field name. So FastEnum provides an API that the value can be quickly obtained from the `EnumMemberAttribute.Value` property.\n\n\n```cs\nenum Company\n{\n    [EnumMember(Value = \"Apple, Inc.\")]\n    Apple = 0,\n}\n\nvar value = Company.Apple.GetEnumMemberValue();  // Apple, Inc.\n```\n\n\n## 3. Adds multiple label annotations to a field\nMultiple attributes can’t be attached to the same field, since `EnumMemberAttribute` is specified `AllowMultiple = false`. It’s inconvenient and I don’t like it personally, so I often use my own `LabelAttribute` as an alternative. You can use it conveniently as follows, because FastEnum provides this feature.\n\n\n```cs\nenum Company\n{\n    [Label(\"Apple, Inc.\")]\n    [Label(\"AAPL\", 1)]\n    Apple = 0,\n}\n\nvar x1 = Company.Apple.GetLabel();   // Apple, Inc.\nvar x2 = Company.Apple.GetLabel(1);  // AAPL\n```\n\n\n\n# Limitation\n## 1. Provides only generics API\nFastEnum provides only generics version method because of performance reason. `System.Enum` provides `System.Type` argument overload, but that’s too slow because of boxing occuration. If you need to use the method that passes `System.Type` type, please use `System.Enum` version.\n\n\n## 2. Can’t parse comma-separated string\n`System.Enum.Parse` can parse like following string. I think that it isn’t well known because it is a specification that exists quietly.\n\n\n```cs\n//--- Assuming there is an enum type like following...\n[Flags]\nenum Fruits\n{\n    Apple = 1,\n    Lemon = 2,\n    Melon = 4,\n    Banana = 8,\n}\n\n//--- Passes comma-separated string\nvar value = Enum.Parse\u003cFruits\u003e(\"Apple, Melon\");\nConsole.WriteLine((int)value);  // 5\n```\n\nIt seems to be a useful function when performing flag processing, but if tries to add such a comma-separated analysis, the overhead will come out, so cutting this feature off makes speed up. I think that in most cases there is no problem, because this feature is rarely used (at least I have NEVER used for 16 years).\n\n\n\n# Why fast ?\nAs you might expect, it’s because cached internally. It takes the approach of Static Type Caching, so the reading cost is almost zero. Based on this, I use techniques for avoiding allocation, and create specialized dictionary for specific key internally. Furthermore, the overwhelming speed is achieved by combining the latest language features of C# with optimized code output through source code generation.\n\n\n\n# Installation\nGetting started from downloading [NuGet](https://www.nuget.org/packages/FastEnum) package.\n\n```\ndotnet add package FastEnum\n```\n\n\n\n# License\nThis library is provided under [MIT License](http://opensource.org/licenses/MIT).\n\n\n# Author\nTakaaki Suzuki (a.k.a [@xin9le](https://twitter.com/xin9le)) is software developer in Japan who awarded Microsoft MVP for Developer Technologies (C#) since July 2012.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxin9le%2Ffastenum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxin9le%2Ffastenum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxin9le%2Ffastenum/lists"}