janmarques / IsoCountries

List of ISO country codes, with their 2-character, 3 character and numeric code. Includes English country name, demonym and adjective.
0 stars 1 forks source link

Alias support #3

Open niemyjski opened 7 years ago

niemyjski commented 7 years ago

Would anyone else find it useful to add aliases for field values. For example there are some really common country full names and even 3 digit codes (e.g., uae). What are the thoughts on this?

janmarques commented 7 years ago

Could be possible, but not a priority at the moment.

Do you have more examples? Let's compose the list here.

niemyjski commented 6 years ago

Here are some of my aliases that I have


        private Country GetByAlias(string name) {
            switch (name.ToLowerInvariant()) {
                case "bngladesh":
                    return GetCountryByAlpha2("BD");
                case "brunei":
                    return GetCountryByAlpha2("BN");
                case "bahamas":
                case "bahamas, the":
                    return GetCountryByAlpha2("BS");
                case "bermud":
                    return GetCountryByAlpha2("BM");
                case "bolivia":
                    return GetCountryByAlpha2("BO");
                case "cana":
                    return GetCountryByAlpha2("CA");
                case "cayman islands b.w.i":
                case "cayman islands":
                    return GetCountryByAlpha2("KY");
                case "curacao":
                    return GetCountryByAlpha2("CW");
                case "cote d’ivoire":
                case "cote d'ivoire-ivory coast":
                    return GetCountryByAlpha2("CI");
                case "czech republic":
                    return GetCountryByAlpha2("CZ");
                case "domini":
                case "dominican republic":
                    return GetCountryByAlpha2("DO");
                case "englnd":
                case "england":
                case "northern ireland":
                case "scotland":
                case "wales":
                case "uk":
                case "un kingdom":
                case "united kingdom":
                    return  GetCountryByAlpha2("GB");
                case "gambia, the":
                    return GetCountryByAlpha2("GM");
                case "germa":
                    return GetCountryByAlpha2("DE");
                case "hgry":
                    return GetCountryByAlpha2("HU");
                case "jpan":
                    return GetCountryByAlpha2("JP");
                case "rok":
                case "korea, south (rok)":
                case "south korea":
                    return GetCountryByAlpha2("KR");
                case "laos":
                    return GetCountryByAlpha2("LA");
                case "macau":
                    return GetCountryByAlpha2("MO");
                case "macedonia (f.y.r.o.m.)":
                    return GetCountryByAlpha2("MK");
                case "moldova":
                    return GetCountryByAlpha2("MD");
                case "neth":
                case "netherlands":
                    return GetCountryByAlpha2("NL");
                case "niger":
                    return GetCountryByAlpha2("NE");
                case "palestine":
                    return GetCountryByAlpha2("PS");
                case "philippines":
                    return GetCountryByAlpha2("PH");
                case "russia":
                    return GetCountryByAlpha2("RU");
                case "samoa (western samoa)":
                    return GetCountryByAlpha2("WS");
                case "spai":
                    return GetCountryByAlpha2("ES");
                case "st. lucia":
                    return GetCountryByAlpha2("LC");
                case "st. kitts and nevis":
                    return GetCountryByAlpha2("KN");
                case "st. vincent & grenadines":
                    return GetCountryByAlpha2("VC");
                case "sudan":
                    return GetCountryByAlpha2("SD");
                case "surinam":
                    return GetCountryByAlpha2("SR");
                case "syria":
                    return GetCountryByAlpha2("SY");
                case "taiwan":
                    return GetCountryByAlpha2("TW");
                case "tahiti":
                    return GetCountryByAlpha2("PF");
                case "tanzania":
                    return GetCountryByAlpha2("TZ");
                case "trinida":
                    return GetCountryByAlpha2("TT");
                case "turk":
                    return GetCountryByAlpha2("TR");
                case "congo, republic of the":
                    return GetCountryByAlpha2("CD");
                case "congo, democratic republc":
                    return GetCountryByAlpha2("CG");
                case "timor leste":
                    return GetCountryByAlpha2("TL");
                case "turks & caicos islands":
                    return GetCountryByAlpha2("TC");
                case "vietnam":
                    return GetCountryByAlpha2("VN");
                case "venezuela":
                    return GetCountryByAlpha2("VE");
                case "uae":
                case "united arab emirates":
                    return GetCountryByAlpha2("AE");
            }

            // return KOSOVO..

            return null;
        }

I also created helpers.... and here is the aliases that I have there

        public Country GetCountryByAlpha2(string code) {
            if (string.IsNullOrEmpty(code))
                throw new ArgumentNullException(nameof(code));

            switch (code.ToLowerInvariant()) {
                case "uk":
                    return GetCountryByAlpha2("GB");
            }

            return Country.Countries.FirstOrDefault(c => c.Alpha2Code == code);
        }

        public Country GetCountryByAlpha3(string code) {
            if (string.IsNullOrEmpty(code))
                throw new ArgumentNullException(nameof(code));

            switch (code.ToLowerInvariant()) {
                case "uae":
                    return GetCountryByAlpha3("ARE");
                case "rok":
                    return GetCountryByAlpha3("KOR");
            }

            return Country.Countries.FirstOrDefault(c => c.Alpha3Code == code);
        }
niemyjski commented 6 years ago

The problem comes when you have ones with the or (, ) as different services might not be in that exact format.