Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CountryInfo Enum

0.00/5 (No votes)
2 May 2015 1  
Key country information in one enum

Introduction

I've been working on a new Multi Channel eCommerce solution which includes accounting software (with the option of Sage). However, as eCommerce & a new Sage 200 developer, I'm always reading XML files and finding it hard to deal with country information. So I decided to country this eNum. It provides the following details:

  1. Int for database
  2. Country code
  3. PhoneCode
  4. Country Name

All in an easy to use eNum, making the code more HCI friendly.

Background

My idea came to a problem I always come across. Before now, I was using XML linq to read XML file each time to check for information about each country. So I decided to change this and make the code more HCI friendly which lead me to create this eNum. This eNum contains 204 countries.

Using the Code

I'm going to keep this nice and sweet. The code uses a custom attribute called CountryInfoAttribute. So if you want to find "secret" and "secret2", then fell free to explore.

How to retrieve country name:

C#
// Return a string of the country name "Falkland Islands"
Country.eCountry.FalklandIslands4FverBritish.GetCountryName();

Know the country but need to know the phone number. Here's how you get the International Codes:

C#
// Returns Int16 international country phone number 44
Country.eCountry.UnitedKingdom.GetPhoneCode();

Need to get the country code. No problem.

C#
// Returns string "US"
Country.eCountry.UnitedStates.GetCountryCode();

You know the country name but you need to get the eNum. You can return the eNum as well.

C#
// Returns eCountry enum.
Country.GetEnum("Vatican City").GetCountryName();

You can also search for the enum by the country code.

C#
// Returns eCountry enum
Country.GetEnum("GB").GetCountryName();

More functions will be coming soon. However, for now, these are the only things I require. As it grows, I'll keep this updated.

Points of Interest

I'm not going to deny I'm a nationalist and patriotic. As a result, some countries have secret and secret2 Attribute value. So, if you play around with the eNum, you might see some quirks.

History

Release 1.0

  • Fetch enum from country code or name
  • eNum contains country code
  • Convert enum into an int to allow for database input
  • Country name
  • International phone numbers

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here