{"id":24435391,"url":"https://github.com/engrajabi/enum.source.generator","last_synced_at":"2025-05-15T15:06:01.869Z","repository":{"id":38196084,"uuid":"496630022","full_name":"EngRajabi/Enum.Source.Generator","owner":"EngRajabi","description":"A C# source generator to create an enumeration class from an enum type. With this package, you can work on enums very, very fast without using reflection.","archived":false,"fork":false,"pushed_at":"2025-04-01T01:35:50.000Z","size":441,"stargazers_count":188,"open_issues_count":15,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-01T04:51:33.739Z","etag":null,"topics":["codegeneration","codegenerator","csharp-sourcegenerator","dotnet","enum-fast","enum-generator","enumgenerator","enums","fast-enum","roslyn","roslyn-generator","source-generator","source-generators"],"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/EngRajabi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://www.buymeacoffee.com/mohsenrajabi"]}},"created_at":"2022-05-26T13:24:37.000Z","updated_at":"2025-02-21T21:37:26.000Z","dependencies_parsed_at":"2024-01-02T22:40:14.988Z","dependency_job_id":"0e30aa05-37e5-4d0a-80a6-ad5e84376abd","html_url":"https://github.com/EngRajabi/Enum.Source.Generator","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngRajabi%2FEnum.Source.Generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngRajabi%2FEnum.Source.Generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngRajabi%2FEnum.Source.Generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngRajabi%2FEnum.Source.Generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EngRajabi","download_url":"https://codeload.github.com/EngRajabi/Enum.Source.Generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247791785,"owners_count":20996830,"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":["codegeneration","codegenerator","csharp-sourcegenerator","dotnet","enum-fast","enum-generator","enumgenerator","enums","fast-enum","roslyn","roslyn-generator","source-generator","source-generators"],"created_at":"2025-01-20T17:20:00.379Z","updated_at":"2025-04-08T06:31:25.393Z","avatar_url":"https://github.com/EngRajabi.png","language":"C#","readme":"﻿[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/EngRajabi/Enum.Source.Generator/master/LICENSE)\n[![Nuget](https://img.shields.io/nuget/dt/Supernova.Enum.Generators?label=Nuget.org%20Downloads\u0026style=flat-square\u0026color=blue)](https://www.nuget.org/packages/Supernova.Enum.Generators)\n[![Nuget](https://img.shields.io/nuget/vpre/Supernova.Enum.Generators.svg?label=NuGet)](https://www.nuget.org/packages/Supernova.Enum.Generators)\n\n\u003cp align=\"center\"\u003e\n \u003ca href=\"https://www.buymeacoffee.com/mohsenrajabi\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-orange.png\" height=\"61\" width=\"194\" /\u003e\n \u003c/a\u003e\n\u003c/p\u003e\n\n\n# Supernova.Enum.Generators\n# The best Source Generator for working with enums in C#\nA C# source generator to create an enumeration class from an enum type.\nWith this package, you can work on enums very, very fast without using reflection.\n\n**Package** - [Supernova.Enum.Generators](https://www.nuget.org/packages/Supernova.Enum.Generators/)\n\nAdd the package to your application using\n\n```bash\ndotnet add package Supernova.Enum.Generators\n```\n\nAdding the package will automatically add a marker attribute, `[EnumGenerator]`, to your project.\n\nTo use the generator, add the `[EnumGenerator]` attribute to an enum. For example:\n\n```csharp\n[EnumGenerator]\npublic enum UserTypeTest\n{\n    [Display(Name = \"مرد\", Description = \"Descمرد\")] Men = 3,\n\n    [Display(Name = \"زن\", Description = \"Descزن\")] Women = 4,\n\n    //[Display(Name = \"نامشخص\")]\n    None\n}\n```\n\nThis will generate a class called `EnumNameEnumExtensions` (`UserTypeTest` + `EnumExtensions`), which contains a number of helper methods.\nFor example:\n\n```csharp\n\n    /// \u003csummary\u003e\n    /// Provides extension methods for operations related to the \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration.\n    /// \u003c/summary\u003e    \n    [GeneratedCodeAttribute(\"Supernova.Enum.Generators\", null)]\n    public static class UserTypeTestEnumExtensions\n    {\n        /// \u003csummary\u003e\n        /// Provides a dictionary that maps \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e values to their corresponding display names.\n        /// \u003c/summary\u003e\n        public static readonly ImmutableDictionary\u003cUnitTests.UserTypeTest, string\u003e DisplayNamesDictionary = new Dictionary\u003cUnitTests.UserTypeTest, string\u003e\n        {\n                {UnitTests.UserTypeTest.Men, \"مرد\"},\n                {UnitTests.UserTypeTest.Women, \"زن\"},\n                {UnitTests.UserTypeTest.None, \"None\"},\n\n        }.ToImmutableDictionary();\n\n        /// \u003csummary\u003e\n        /// Provides a dictionary that maps \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e values to their corresponding descriptions.\n        /// \u003c/summary\u003e\n        public static readonly ImmutableDictionary\u003cUnitTests.UserTypeTest, string\u003e DisplayDescriptionsDictionary = new Dictionary\u003cUnitTests.UserTypeTest, string\u003e\n        {\n                {UnitTests.UserTypeTest.Men, \"Descمرد\"},\n                {UnitTests.UserTypeTest.Women, \"Descزن\"},\n                {UnitTests.UserTypeTest.None, \"None\"},\n\n        }.ToImmutableDictionary();\n\n        /// \u003csummary\u003e\n        /// Converts the \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration value to its string representation.\n        /// \u003c/summary\u003e\n        /// \u003cparam name=\"states\"\u003eThe \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration value.\u003c/param\u003e\n        /// \u003cparam name=\"defaultValue\"\u003eThe default value to return if the enumeration value is not recognized.\u003c/param\u003e\n        /// \u003creturns\u003eThe string representation of the \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value.\u003c/returns\u003e\n        public static string ToStringFast(this UnitTests.UserTypeTest states, string defaultValue = null)\n        {\n            return states switch\n            {\n                UnitTests.UserTypeTest.Men =\u003e nameof(UnitTests.UserTypeTest.Men),\n                UnitTests.UserTypeTest.Women =\u003e nameof(UnitTests.UserTypeTest.Women),\n                UnitTests.UserTypeTest.None =\u003e nameof(UnitTests.UserTypeTest.None),\n                _ =\u003e defaultValue ?? throw new ArgumentOutOfRangeException(nameof(states), states, null)\n            };\n        }\n\n        /// \u003csummary\u003e\n        /// Checks if the specified \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value is defined.\n        /// \u003c/summary\u003e\n        /// \u003cparam name=\"states\"\u003eThe \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value to check.\u003c/param\u003e\n        /// \u003creturns\u003eTrue if the \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value is defined; otherwise, false.\u003c/returns\u003e\n        public static bool IsDefinedFast(UnitTests.UserTypeTest states)\n        {\n            return states switch\n            {\n                UnitTests.UserTypeTest.Men =\u003e true,\n                UnitTests.UserTypeTest.Women =\u003e true,\n                UnitTests.UserTypeTest.None =\u003e true,\n                _ =\u003e false\n            };\n        }\n\n        /// \u003csummary\u003e\n        /// Checks if the specified string represents a defined \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value.\n        /// \u003c/summary\u003e\n        /// \u003cparam name=\"states\"\u003eThe string representing a \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value.\u003c/param\u003e\n        /// \u003creturns\u003eTrue if the string represents a defined \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value; otherwise, false.\u003c/returns\u003e\n        public static bool IsDefinedFast(string states)\n        {\n            return states switch\n            {\n                nameof(UnitTests.UserTypeTest.Men) =\u003e true,\n                nameof(UnitTests.UserTypeTest.Women) =\u003e true,\n                nameof(UnitTests.UserTypeTest.None) =\u003e true,\n                _ =\u003e false\n            };\n        }\n\n        /// \u003csummary\u003e\n        /// Converts the \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration value to its display string.\n        /// \u003c/summary\u003e\n        /// \u003cparam name=\"states\"\u003eThe \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration value.\u003c/param\u003e\n        /// \u003cparam name=\"defaultValue\"\u003eThe default value to return if the enumeration value is not recognized.\u003c/param\u003e\n        /// \u003creturns\u003eThe display string of the \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value.\u003c/returns\u003e\n        public static string ToDisplayFast(this UnitTests.UserTypeTest states, string defaultValue = null)\n        {\n            return states switch\n            {\n                UnitTests.UserTypeTest.Men =\u003e \"مرد\",\n                UnitTests.UserTypeTest.Women =\u003e \"زن\",\n                UnitTests.UserTypeTest.None =\u003e \"None\",\n                _ =\u003e defaultValue ?? throw new ArgumentOutOfRangeException(nameof(states), states, null)\n            };\n        }\n\n        /// \u003csummary\u003e\n        /// Gets the description of the \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration value.\n        /// \u003c/summary\u003e\n        /// \u003cparam name=\"states\"\u003eThe \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration value.\u003c/param\u003e\n        /// \u003cparam name=\"defaultValue\"\u003eThe default value to return if the enumeration value is not recognized.\u003c/param\u003e\n        /// \u003creturns\u003eThe description of the \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value.\u003c/returns\u003e\n        public static string ToDescriptionFast(this UnitTests.UserTypeTest states, string defaultValue = null)\n        {\n            return states switch\n            {\n                UnitTests.UserTypeTest.Men =\u003e \"Descمرد\",\n                UnitTests.UserTypeTest.Women =\u003e \"Descزن\",\n                UnitTests.UserTypeTest.None =\u003e \"None\",\n                _ =\u003e defaultValue ?? throw new ArgumentOutOfRangeException(nameof(states), states, null)\n            };\n        }\n\n        /// \u003csummary\u003e\n        /// Retrieves an array of all \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration values.\n        /// \u003c/summary\u003e\n        /// \u003creturns\u003eAn array containing all \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration values.\u003c/returns\u003e\n        public static UnitTests.UserTypeTest[] GetValuesFast()\n        {\n            return new[]\n            {\n                UnitTests.UserTypeTest.Men,\n                UnitTests.UserTypeTest.Women,\n                UnitTests.UserTypeTest.None,\n            };\n        }\n\n        /// \u003csummary\u003e\n        /// Retrieves an array of strings containing the names of all \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration values.\n        /// \u003c/summary\u003e\n        /// \u003creturns\u003eAn array of strings containing the names of all \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration values.\u003c/returns\u003e\n        public static string[] GetNamesFast()\n        {\n            return new[]\n            {\n                nameof(UnitTests.UserTypeTest.Men),\n                nameof(UnitTests.UserTypeTest.Women),\n                nameof(UnitTests.UserTypeTest.None),\n            };\n        }\n\n        /// \u003csummary\u003e\n        /// Gets the length of the \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration.\n        /// \u003c/summary\u003e\n        /// \u003creturns\u003eThe length of the \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e enumeration.\u003c/returns\u003e\n        public static int GetLengthFast()\n        {\n            return 3;\n\n        }\n\n        /// \u003csummary\u003e\n        /// Try parse a string to \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value.\n        /// \u003c/summary\u003e\n        /// \u003cparam name=\"states\"\u003eThe string representing a \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e value.\u003c/param\u003e\n        /// \u003cparam name=\"result\"\u003eThe enum \u003csee cref=\"global::UnitTests.UserTypeTest\" /\u003e parse result.\u003c/param\u003e\n        /// \u003creturns\u003eTrue if the string is parsed successfully; otherwise, false.\u003c/returns\u003e\n        public static bool TryParseFast(string states, out UnitTests.UserTypeTest result)\n        {\n            switch (states)\n            {\n                case \"Men\": \n                {\n                    result = UnitTests.UserTypeTest.Men;\n                    return true;\n                }\n                case \"Women\": \n                {\n                    result = UnitTests.UserTypeTest.Women;\n                    return true;\n                }\n                case \"None\": \n                {\n                    result = UnitTests.UserTypeTest.None;\n                    return true;\n                }\n                default: {\n                    result = default;\n                    return false;\n                }\n            }\n        }\n    }\n```\n\nYou do not see this file inside the project. But you can use it.\n\nUsage\n```csharp\nvar stringEnum = UserTypeTest.Men.ToStringFast(); //Men;\n\nvar isDefined = UserTypeTestEnumExtensions.IsDefinedFast(UserType.Men); //true;\n\nvar displayEnum = UserTypeTest.Men.ToDisplayFast(); //مرد\n\nvar descriptionEnum = UserTypeTest.Men.ToDescriptionFast(); //Descمرد\n\nvar names = UserTypeTestEnumExtensions.GetNamesFast(); //string[]\n\nvar values = UserTypeTestEnumExtensions.GetValuesFast(); //UserType[]\n\nvar length = UserTypeTestEnumExtensions.GetLengthFast(); //3\n\nvar menString = \"Men\";\nvar result = UserTypeTestEnumExtensions.TryParseFast(menString, out var enumValue);\n```\n\nIf you had trouble using UserTypeTestEnumExtensions and the IDE did not recognize it. This is an IDE problem and you need to restart the IDE once.\n\nBenchmark\n\n![Benchmark](https://raw.githubusercontent.com/EngRajabi/Enum.Source.Generator/master/Supernova.Enum.Generators.png?v=4)\n\n## Contributing\n\nCreate an [issue](https://github.com/EngRajabi/Enum.Source.Generator/issues/new) if you find a BUG or have a Suggestion or Question. If you want to develop this project :\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request\n\n## Give a Star! ⭐️\n\nIf you find this repository useful, please give it a star. Thanks!\n\n## License\n\nSupernova.Enum.Generators is Copyright © 2022 [Mohsen Rajabi](https://github.com/EngRajabi) under the MIT License.\n","funding_links":["https://www.buymeacoffee.com/mohsenrajabi"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengrajabi%2Fenum.source.generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fengrajabi%2Fenum.source.generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengrajabi%2Fenum.source.generator/lists"}