public CountryEnumValue(string countryString) { if (string.IsNullOrWhiteSpace(countryString)) { throw new ArgumentNullException(nameof(countryString)); } var length = countryString.Length; if (length == 2 || length == 3) { var country = CountryManager.GetCountryInfo(countryString); if (country != null) { _countryEnum = country.Country; _countryEnumString = countryString; _countryInfo = country; return; } } var enumMember = Enums.GetMember <Country>(countryString, true); if (enumMember != null) { _countryEnum = enumMember.Value; _countryEnumString = countryString; _countryInfo = CountryManager.GetCountryInfo(_countryEnum); return; } //历史国家的 Name 应当是 国名+建国年,比如 Yugoslavia1992 if (countryString.Length <= 4) { throw new ArgumentException("The length of the countryString must greater than 4."); } #if NETSTANDARD2_0 var year = countryString.Substring(countryString.Length - 4).CastToInt32(-1); var countryStr = countryString.Substring(0, countryString.Length - 4); #else var year = countryString[^ 4..].CastToInt32(-1);
/// <summary> /// To country info /// </summary> /// <returns></returns> public CountryInfo ToCountryInfo() { return(CountryManager.GetCountryInfo(Alpha2Code)); }
public static RuntimeCountryInfo Of(string alphaCode) => Of(CountryManager.GetCountryInfo(alphaCode));
public static RuntimeCountryInfo Of(long cep1CrCode) => CountryManager.GetCountryInfo(cep1CrCode);
public static RuntimeCountryInfo Of(RegionCodeValue code) => CountryManager.GetCountryInfo(code);
public static RuntimeCountryInfo Of(CountryCode code) => Of(CountryManager.GetCountryInfo(code));
public static RuntimeCountryInfo Of(Country country) => Of(CountryManager.GetCountryInfo(country));
/// <summary> /// Convert <see cref="CountryCode"/> to <see cref="CountryInfo"/>. /// </summary> /// <param name="code"></param> /// <returns></returns> public static CountryInfo ToInfo(this CountryCode code) { return(CountryManager.GetCountryInfo(code)); }
/// <summary> /// Get Alpha3 code from <see cref="Country"/>. /// </summary> /// <param name="country"></param> /// <returns></returns> public static string GetAlpha3Code(this Country country) { return(CountryManager.GetCountryInfo(country).Alpha3Code); }
/// <summary> /// Convert <see cref="Country"/> to <see cref="CountryInfo"/>. /// </summary> /// <param name="country"></param> /// <returns></returns> public static CountryInfo ToInfo(this Country country) { return(CountryManager.GetCountryInfo(country)); }
/// <summary> /// Get Alpha2 code from <see cref="CountryCode"/>. /// </summary> /// <param name="code"></param> /// <returns></returns> public static string GetAlpha2Code(this CountryCode code) { return(CountryManager.GetCountryInfo(code).Alpha2Code); }
public CountryEnumValue(Country country) { _countryEnum = country; _countryEnumString = country.GetName(); _countryInfo = CountryManager.GetCountryInfo(country); }