• Stars
    star
    285
  • Rank 144,434 (Top 3 %)
  • Language
    C#
  • License
    MIT License
  • Created about 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚡Offline dotnet standard library to get information about countries

IconRESTCountries.NET v3.0.0

A completely offline library to get information about countries.

Documentation of the previous versions can be found here.

Setup

Version 3 features

Features v2.x.x Current version
Offline support ✔️
More translation languages ✔️
Country postal code with regex ✔️
Google Maps and OpenStreetMap location ✔️
Country flag in unicode, png and svg format Unicode not supported ✔️
Time zones information ✔️
Car information ✔️
Start of the week ✔️
Mobile phone prefix information ✔️

Benchmark

Note

Add namespace RESTCountries.NET.Services and call RestCountriesService class to access all methods.

Each method returns an object of type Country or a IEnumerable of Country. You can apply filters on the returned value to retrieve what you need.

Example:

  • Just get name and capital city of all countries.
  • Get country names in French language or Spanish language.

The default language for the country name is English, but you can also get the name in other languages such as: Arabic, Breton, Czech, Welsh, German, Estonian, Finnish, French, Croatian, Hungarian, Italian, Japanese, Korean, Dutch, Persian, Polish, Russian, Slovak, Spanish, Swedish, Turkish, Urdu and Chinese.

Usage

Note: The list is already ordered ascending by the country name.

  • Get all countries
// Get all countries
IEnumerable<Country> countries = RestCountriesService.GetAllCountries();
  • Search by country name containing a "prefix"
// Search by country name containing "a" or "A"
IEnumerable<Country> result = RestCountriesService.GetCountriesByNameContains("a");
  • Search by country full name
// Search by country full name
Country? result = GetCountryByFullName("Brazil");
  • Search by Alpha-2 code or Alpha-3 code
// Search by country code
Country? result = RestCountriesService.GetCountryByCode("us"); // or USA
  • Search by currency code, name or symbol
// Search by currency code, name or symbol
IEnumerable<Country> result = RestCountriesService.GetCountriesByCurrency("EUR"); // Or Euro or €
  • Search by language
// Search by language
IEnumerable<Country> result = RestCountriesService.GetCountriesByLanguage("french"); // or fra

You can use var instead of explicit types. I use explicit types to show you the return type of each method.

  • Get only country names
var result = RestCountriesService.GetAllCountriesNames().ToList();

Here, you can choose the language you want. check out the the TranslationLanguage class to see the available languages.

//  Get country names in French langauge
List<string> result = RestCountriesService.GetAllCountriesNames(TranslationLanguage.French).ToList();

Country class

public class Country
{
    /// <summary>
    /// Country name
    /// </summary>
    public CountryName Name { get; set; }

    /// <summary>
    /// Top Level Domain of the country.
    /// </summary>
    public string[]? Tld { get; set; }

    /// <summary>
    /// The alpha-2 code of the country.
    /// </summary>
    public string Cca2 { get; set; }

    /// <summary>
    /// ISO 3166-1 numeric : https://en.wikipedia.org/wiki/ISO_3166-1_numeric
    /// </summary>
    public string? Ccn3 { get; set; }

    /// <summary>
    /// The alpha-3 code of the country.
    /// </summary>
    public string Cca3 { get; set; }

    /// <summary>
    /// International Olympic Committee Code.
    /// </summary>
    public string Cioc { get; set; }
    
    /// <summary>
    /// Is the country independent?
    /// </summary>
    public bool? Independent { get; set; }

    /// <summary>
    /// Status of the country. check out the https://restcountries.com/ for more info.
    /// </summary>
    public string? Status { get; set; }

    /// <summary>
    /// Is the country member of the United Nations ?
    /// </summary>
    public bool UnMember { get; set; }

    /// <summary>
    /// Currencies used in the country.
    /// The dictionary is the currency code, the value is a Currency
    /// object: {name: string, symbol: string}.
    /// </summary>
    public Dictionary<string, Currency>? Currencies { get; set; }

    /// <summary>
    /// International direct dialing.
    /// </summary>
    public Idd Idd { get; set; }

    /// <summary>
    /// Capital(s) of the country.
    /// </summary>
    public string[] Capital { get; set; }

    /// <summary>
    /// Alternative spellings of the country.
    /// </summary>
    public string[] AltSpellings { get; set; }

    /// <summary>
    /// Region of the country (eg. Africa, Americas, Asia, Europe, Oceania, Antarctic).
    /// </summary>
    public string Region { get; set; }

    /// <summary>
    /// The subregion of the country(eg. Western Africa, Western Europe, ...)
    /// <remarks>Can be null.</remarks>
    /// </summary>
    public string? Subregion { get; set; }

    /// <summary>
    /// Languages spoken in the country.
    /// The key of the dictionary is the language code, the value is a
    /// the language name in english.
    /// </summary>
    public Dictionary<string, string>? Languages { get; set; }

    /// <summary>
    /// Translations of the country name in other languages
    /// </summary>
    public Dictionary<string, Translation> Translations { get; set; }

    /// <summary>
    /// Gps coordinates of the country in the format: [latitude, longitude].
    /// </summary>
    private double[] LatLng { get; set; }

    /// <summary>
    /// Is the country landlocked?
    /// </summary>
    public bool Landlocked { get; set; }

    /// <summary>
    /// Neighboring countries.
    /// </summary>
    public string[] Borders { get; set; }

    /// <summary>
    /// The area of the country in square kilometers.
    /// </summary>
    public double? Area { get; set; }

    /// <summary>
    /// Demonym.
    /// </summary>
    public Demonyms? Demonyms { get; set; }
    
    /// <summary>
    /// Unicode flag.
    /// </summary>
    public string UnicodeFlag { get; set; }

    /// <summary>
    /// Google maps or OpenStreetMap link.
    /// </summary>
    public Maps Maps { get; set; }

    /// <summary>
    /// FIFA code.
    /// </summary>
    public string? Fifa { get; set; }

    /// <summary>
    /// Car information.
    /// </summary>
    public Car? Car { get; set; }
    
    /// <summary>
    /// List of timezones.
    /// </summary>
    public string[] Timezones { get; set; }

    /// <summary>
    /// Continent of the country. Only one continent is possible.
    /// The data source taken from https://restcountries.com/ return a list of
    /// one continent. That's why it's an array.
    /// </summary>
    public string[] Continents { get; set; }

    /// <summary>
    /// Flag(Url) of the country in png and svg format.
    /// </summary>
    public Flag Flag { get; set; }

    /// <summary>
    /// The week start by which day ? (eg. Sunday, Monday, ...)
    /// </summary>
    public string StartOfWeek { get; set; }

    /// <summary>
    /// Capital details. (eg. latitude, longitude, ...)
    /// </summary>
    public CapitalInformation CapitalInformation { get; set; }

    /// <summary>
    /// Postal code information (eg. format, regex).
    /// </summary>
    public PostalCode? PostalCode { get; set; }
}

Issues

If you find an error in the data source, please create an issue on the restcountries.com repo available on GitLab(https://gitlab.com/amatos/rest-countries), where our local data comes from.

Created by: Laurent Egbakou

License

The MIT License (MIT) see License file

Contribution

Pull requests are more than welcome! If you do submit one, please make sure to read the contributing guidelines first.

More Repositories

1

WhatsAppUI

WhatsApp UI in Xamarin.Forms
C#
302
star
2

FurnitureShop3d

Xamrin.Forms UI Challenge
C#
81
star
3

CreditCardCheckout

Credit Card Checkout - A Xamarin.Forms UI Challenge
C#
74
star
4

domainverifier-dotnet

domain name ownership verification library written in C#/.NET ✔️
C#
40
star
5

Timeline

Awesome UI: Timeline with images in Xamarin.Forms.
C#
34
star
6

App.User.LocationInfo

Tracking Plugin for Xamarin. It retrieves information about user's location without GPS activation: IP address, country name, city name, GPS coordinates (latitude and longitude), country calling code, country currency, country flag image, etc.
C#
27
star
7

domainverifier

domain name ownership verification library written in Go ✔️
Go
26
star
8

reedsolomon

Reed-Solomon Erasure Coding in C#/.NET
C#
24
star
9

ExportDataToExcel

Export Xamarin.Forms ListView Items to Excel File.
C#
18
star
10

BarCodeReader

Barcodes reader Project in Xamarin.Froms.
C#
16
star
11

FingerPrintXamarin

Fingerprint authentication example in Xamarin.Forms.
C#
16
star
12

TrackXamarinAppUser

Xamarin.Forms Sample project using App.User.LocationInfo plugin. As a reminder, the Plugin App.User.LocationInfo retrieves information about user's location without GPS activation: IP address, country name, city name, GPS coordinates (latitude and longitude), country calling code, country currency, country flag image, etc.
C#
15
star
13

EmojisInXamarinForms

Use of Emojis in Xamarin.Forms 🤓🤔👨 🤹‍
C#
14
star
14

coronavirus-tg-api

API for tracking the global coronavirus (COVID-19, SARS-CoV-2) 🦠 outbreak in Togo. It's written in python using the FastAPI framework 🔥. Supports government source!
Python
14
star
15

ColorPicker

Custom Color picker project in Xamarin.Forms
C#
7
star
16

VlcXamSample

A sample demonstrates how to use and customize the LibVLCSharp MediaElement control.
C#
6
star
17

StatusBar

Manage to hide or show smarphone's status bar in Xamarin.Forms
C#
6
star
18

ICSFileReader

Read data from remote ICalendar file
C#
6
star
19

EventToCommand

Create Behavior that convert Event to bindable Command
C#
5
star
20

Covid19Tracker.NET

.NET Standard wrapper arrond the api provided by https://github.com/NovelCovid/API
C#
5
star
21

SendGridEmail

Send Email using SendGrid
C#
4
star
22

CustomXamarinStepper

Xamarin Stepper with Entry.
C#
4
star
23

remote-ftp-server

Connect to a remote FTP Server.
C#
3
star
24

FormValidation

Real time form validation using Triggers and Converters in Xamarin.Forms
C#
3
star
25

AdvancedNetCoreApi

.NET Core API: Generic and dynamically generated controllers using Dynamic DBContext.
C#
3
star
26

novelcovid-api-badges

Svg badges displaying the number of coronavirus confirmed cases, recovered and deaths.
JavaScript
3
star
27

marathon-compilers

Compilation library for programming competitions. This library can be used to configure online compilers or to set up a platform for compiling and running programs during programming competitions.
Java
3
star
28

interactive-monitoring-network

Use vis.js to draw an interactive monitoring network.
JavaScript
2
star
29

user-location

Get user's country name and country fag based on his ip address
HTML
2
star
30

login-page-validation-using-JQuery

Validate login page entries using JQuery
JavaScript
1
star
31

trackmanagement-app-crashing

C#
1
star
32

dotnet6-integration-tests

.NET 6 API with Integration tests
C#
1
star