Click here to Skip to main content
15,868,016 members
Articles / Programming Languages / C#
Reference

CountryInfo Enum

Rate me:
Please Sign up or sign in to vote.
3.11/5 (13 votes)
2 May 2015Public Domain2 min read 24.1K   393   5   10
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, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Software Developer
United Kingdom United Kingdom
I'm a Software and web developer with experience in multiple languages from C# to PHP to Java. I believe in Free software and an associated Member of Free Software Foundation.

Comments and Discussions

 
QuestionMy vote of #2 Pin
BillWoodruff17-Feb-16 20:34
professionalBillWoodruff17-Feb-16 20:34 
QuestionMy vote of 500 Pin
R. Giskard Reventlov4-May-15 5:04
R. Giskard Reventlov4-May-15 5:04 
AnswerRe: My vote of 500 Pin
BillWoodruff17-Feb-16 20:22
professionalBillWoodruff17-Feb-16 20:22 
GeneralMy vote of 3 Pin
fredatcodeproject3-May-15 4:31
professionalfredatcodeproject3-May-15 4:31 
GeneralRe: My vote of 3 Pin
Jordan Hall3-May-15 5:31
Jordan Hall3-May-15 5:31 
GeneralRe: My vote of 3 Pin
fredatcodeproject3-May-15 6:03
professionalfredatcodeproject3-May-15 6:03 
GeneralRe: My vote of 3 Pin
Jordan Hall3-May-15 9:19
Jordan Hall3-May-15 9:19 
GeneralRe: My vote of 3 Pin
fredatcodeproject3-May-15 21:36
professionalfredatcodeproject3-May-15 21:36 
GeneralMy vote of 1 Pin
InbarBarkai3-May-15 0:04
InbarBarkai3-May-15 0:04 
GeneralRe: My vote of 1 Pin
Jordan Hall3-May-15 0:36
Jordan Hall3-May-15 0:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.