CountryData.Standard 1.5.0

dotnet add package CountryData.Standard --version 1.5.0                
NuGet\Install-Package CountryData.Standard -Version 1.5.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CountryData.Standard" Version="1.5.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CountryData.Standard --version 1.5.0                
#r "nuget: CountryData.Standard, 1.5.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CountryData.Standard as a Cake Addin
#addin nuget:?package=CountryData.Standard&version=1.5.0

// Install CountryData.Standard as a Cake Tool
#tool nuget:?package=CountryData.Standard&version=1.5.0                

A cross-platform library designed to provide seamless access to global country data for .NET applications without making any http calls. Our aim is to simplify the process of integrating standardised global data into your applications, making it an ideal tool for developers who require international data.

Project Status

nuget downloads alternate text is missing from this package README image
builds .NET
code coverage codecov
code quality Quality Gate Status

Features

  • 🌍 Get global country data [CountryName, CountryPhone, Region, CountryFlag, PhoneCode ]
  • πŸ³οΈβ€πŸŒˆ Get country data by ISO 3166 country code
  • 🚩 Get country flag by ISO 3166 country code
  • πŸ—ΊοΈ Get country region by ISO 3166 country code
  • ☎️ Get country phone code by ISO 3166 country code

Install Library

Package Manager
   PM> Install-Package CountryData.Standard -Version 1.5.0
.NET CLI
   > dotnet add package CountryData.Standard --version 1.5.0

Usage

CountryData.Standard is a robust, production-grade package designed for a wide range of .NET applications. Whether you're developing a .NET Core Web API, a console application, a .NET MAUI or Xamarin app, a Blazor project, or a mobile app, this library is built to seamlessly integrate with your project.

To get started quickly, check out our Sample Code. This section provides practical examples of how to use the library in various types of projects.

For more detailed instructions and comprehensive information about the library, please refer to our Documentation. This resource offers in-depth guidance on how to effectively use the CountryData.Standard library in your projects.

Methods and Descriptions

The CountryData.Standard library provides a set of methods that allow you to retrieve country data, flags, regions, and phone codes. The following table lists the available methods and their descriptions.

Method Description
GetCountryData() Returns all country data including region, short code, and country name.
GetCountryByCode(string shortCode) Returns a single country's data by its short code.
GetCountryEmojiFlag(string shortCode) Gets the flag of the country, represented as an emoji, by the country's short code.
GetRegionByCountryCode(string shortCode) Selects and returns a list of regions for a particular country identified by its short code.
GetCountries() Gets the list of all country names.
GetPhoneCodeByCountryShortCode(string shortCode) Returns a single country's phone code by its short code.
GetCountryByPhoneCode(string phoneCode) Returns country data for the country associated with the specified phone code.
GetCurrencyCodesByCountryCode(string shortCode) Returns a list of currency codes for a specific country identified by its short code.
GetCountryByCurrencyCode(string currencyCode) Returns a list of countries that use the specified currency code.
GetCountryCode(string countryName) Returns the country code for a specific country name.

Initialize the Country data object

       //loads all Country Data via the constructor (You can initialize this once as a singleton)
       var helper = new CountryHelper();

Get list of Countries

       var countries = helper.GetCountries();
       foreach (var country in countries) 
         Console.WriteLine(country);

Get list of Regions in a Country by Country Code

       var regions = helper.GetRegionByCountryCode("GH");
       foreach (var region in regions)
         Console.WriteLine(region.Name);

Using lambda for custom querries

GetCountryData() returns an IEnumerable<Country> which can be querried with Lambda for a more flexible usage.
      //example1
      var data = helper.GetCountryData();
       //get list of countries by their Names
      var countries = data.Select(c => c.CountryName).ToList();
       foreach (var country in countries)
         Console.WriteLine(country);
       
      
       //example 2
       data.Where(x => x.CountryShortCode == "US")
                              .Select(r=>r.Regions).FirstOrDefault()
                              .ToList();

Get Country Data by Country Code

This example demonstrates how to retrieve a country with a specific phone code using the GetCountryByPhoneCode method. In this case, we're fetching the country with the phone code "+233".

var CountryName = helper.GetCountryByPhoneCode("+233");
Console.WriteLine(CountryName);

ISO-3166-1 country codes

For a list of supported ISO-3166-1 country codes, PhoneCode, Flags, ISO and , Unicode please refer to the Country Details file.

Contributing

Contributions are welcome! We value your input and want to make contributing to this project as easy and transparent as possible. Please see our Contributing Guide for more details.

Code of Conduct

We are committed to fostering a welcoming and respectful community for everyone. Our Code of Conduct outlines the standards of behavior expected from contributors and maintainers. This document helps ensure that the community around our project is inclusive and collaborative. Please refer to our code of conduct for more information.

Comming Soon

  • Support for ISO 3166 Country A3 Codes
  • Country ShortCode Enums

License

This project is licensed under the terms of the LICENSE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on CountryData.Standard:

Repository Stars
unoplatform/Uno.Samples
A collection of code samples for the Uno Platform
frankodoom/CountryData.Net
An offline crossplatform .NET library for getting Global Country , iso3166 Short-code and Region Data
Version Downloads Last updated
1.5.0 1,369 11/12/2024
1.4.1 13,997 6/7/2024
1.3.0 95,718 5/18/2022
1.2.0 1,220 5/3/2022
1.0.1 142,608 11/26/2019