{"id":26103608,"url":"https://github.com/sic42/countryinfos","last_synced_at":"2025-10-09T19:46:35.471Z","repository":{"id":281268473,"uuid":"944759548","full_name":"SiC42/CountryInfos","owner":"SiC42","description":"Provides compiled country information","archived":false,"fork":false,"pushed_at":"2025-03-22T15:56:37.000Z","size":93,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-03T07:53:31.373Z","etag":null,"topics":["country","country-codes","dotnet","iso3166","sourcegenerator"],"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/SiC42.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}},"created_at":"2025-03-07T23:09:22.000Z","updated_at":"2025-03-22T15:54:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"6b8903fc-4c29-4550-bbc5-d8be4e9d472a","html_url":"https://github.com/SiC42/CountryInfos","commit_stats":null,"previous_names":["sic42/countryinfos"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/SiC42/CountryInfos","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiC42%2FCountryInfos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiC42%2FCountryInfos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiC42%2FCountryInfos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiC42%2FCountryInfos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SiC42","download_url":"https://codeload.github.com/SiC42/CountryInfos/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiC42%2FCountryInfos/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001959,"owners_count":26083244,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["country","country-codes","dotnet","iso3166","sourcegenerator"],"created_at":"2025-03-09T20:41:50.895Z","updated_at":"2025-10-09T19:46:35.460Z","avatar_url":"https://github.com/SiC42.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Country Info Generator\n\nThe BCL (Base Class Library) only has the `RegionInfo` and `CultureInfo` classes to represent countries and cultures.\nUnfortunately, the data representation (using mainly strings) can make handling conversions between different formats error-prone.\n\nThis project aims to create a source generator that generates a C# class for each country, with properties for the country's name, ISO code, and other relevant information.\nIt uses the BCL's `RegionInfo` and `CultureInfo` class to get the data.\nAdditionally, a second nuget package is present that contains the generated data.\n\n## Installation\nYou may install the package from NuGet:\n```bash\ndotnet add package Sic.CountryInfos\n```\n\nIf you prefer to use the source generator, with which the namespace and the contained data can be configured, see [Source Generator](#source-generator).\n\n## Usage\nThere are three enums representing the country's data:\n- `Country`: Contains the english name of the country (spaces and special characters omitted).\n- `CountryIso2Code`: Contains the ISO 3166-1 alpha-2 code of the country.\n- `CountryIso3Code`: Contains the ISO 3166-1 alpha-3 code of the country.\n\nAll enums use the GeoId (which is the same as the `RegionInfo`'s `GeoId`) as the enum value.\nAdditionally, there is a `IsSameCountry`-extension method that checks if two (different) enums represent the same country, e.g.:\n```csharp\nbool isSameCountry = Country.Germany.IsSameCountry(CountryIso2CodeName.DE); // true\n```\n\nAdditionally, there is a `LocaleCode` enum that contains the locale code of the countries. The values represent the LCID (Locale Identifier) value.\n```csharp\n    /// \u003csummary\u003e\n    /// Afrikaans (South Africa) - af-ZA\n    /// \u003c/summary\u003e\n    af_ZA = 1078,\n    /// \u003csummary\u003e\n    /// Amharic (Ethiopia) - am-ET\n    /// \u003c/summary\u003e\n    am_ET = 1118\n```\n\n\nAll this information is additionally present in the `CountryInfo` class. An instance of this class can be created by using the `CountryInfo.Get`-method:\n```csharp\nCountryInfo germany = CountryInfo.Get(Country.Germany);\n// or\ngermany = CountryInfo.Get(CountryIso2Code.DE);\n// or\ngermany = CountryInfo.Get(CountryIso3Code.DEU);\n// or\ngermany = CountryInfo.Get(LocaleCode.de_DE);\n```\nThe `CountryInfo` can than be used to get the country's name, ISO codes, and other information.\n```csharp\ngermany.EnglishName; // Germany as string\nCountry country = germany.Country; // Country.Germany\nCountryIso2Code iso2Code = germany.TwoLetterIsoCode; // CountryIso2CodeName.DE\nCountryIso3Code iso3Code = germany.ThreeLetterIsoCode; // CountryIso3CodeName.DEU\nIReadOnlyList\u003cLocaleCode\u003e supportedLocales = germany.SupportedLocales; // [LocaleCode.de_DE, LocaleCode.dsb_DE, ...]\n```\n\nAdditionally, the `CountryInfo` class contains a `All`-property that contains a list of all countries.\n\nThere are also extensions for the `Country`, `CountryIso2Code`, `CountryIso3Code`, and `LocaleCode` enums that allow getting the `CountryInfo` instance directly:\n```csharp\nCountryInfo germany = Country.Germany.GetCountryInfo();\n```\n\n## Source Generator\nYou might want to use the source generator, if you would like to\n- change the root namespace of the generated classes\n- filter the countries (and its locales) that should be generated\n\n⚠ As the source generator uses the `CultureInfo` implementation to get the data,\nthe output is dependent on your installed culture info data on your OS.\n\nInstall the generator via\n```bash\ndotnet add package Sic.CountryInfos.SourceGenerator\n```\n\n### Filter Countries\nYou can filter the countries that should be generated \nby providing a list of either a `Country.Countries.txt`, `CountryIso2Code.Countries.txt`, \nor `CountryIso3Code.Countries.txt` enum names, e.g. for `CountryIso2Code.Countries.txt`:\n```\nDE\nAT\nBE\nSE\n```\nThe file has to be added as Additional File in the project file:\n```xml\n\u003cItemGroup\u003e\n    \u003cNone Remove=\"CountryIso2Code.Countries.txt\"/\u003e\n    \u003cAdditionalFiles Include=\"CountryIso2Code.Countries.txt\"/\u003e\n\u003c/ItemGroup\u003e\n```\nThe source generator will then generate all enums only for the countries (and its locales) that are listed in the file.\n\n### Change Root Namespace\nOn default, the generator will generate the classes in the root namespace of your project.\nIf you want to change the namespace, you can add the `SicCountryInfosCustomNamespace` property to your project file:\n```xml\n\u003cItemGroup\u003e\n       \u003cCompilerVisibleProperty Include=\"SicCountryInfosCustomNamespace\" /\u003e\n\u003c/ItemGroup\u003e\n\n\u003cPropertyGroup\u003e\n   \u003cSicCountryInfosCustomNamespace\u003eMy.Custom.Namespace\u003c/SicCountryInfosCustomNamespace\u003e\n\u003c/PropertyGroup\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsic42%2Fcountryinfos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsic42%2Fcountryinfos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsic42%2Fcountryinfos/lists"}