/// <summary>   Formats an unformatted phone number, and adds country code if country is
        ///             supplied. </summary>
        /// <remarks>   Sander.struijk, 25.02.2014. </remarks>
        /// <exception cref="ArgumentNullException">    Thrown when one or more required arguments are
        ///                                             null. </exception>
        /// <param name="phoneNumber">  The phone number. </param>
        /// <param name="countryName">      (Optional) The country. </param>
        /// <returns>   The formatted value. </returns>
        public static string Format(string phoneNumber, string countryName = "")
        {
            CountryMetaDataRetriever.Initialize();
            if (string.IsNullOrEmpty(phoneNumber))
            {
                throw new ArgumentNullException("phoneNumber");
            }
            var countryMetaData      = GetCountryMetaData(countryName);
            var formattedPhoneNumber = new PhoneNumber(countryMetaData, phoneNumber).ToString();

            return(formattedPhoneNumber);
        }
Exemplo n.º 2
0
 /// <summary>   Formats an unformatted phone number, and adds country code if country is
 ///             supplied. </summary>
 /// <remarks>   Sander.struijk, 25.02.2014. </remarks>
 /// <exception cref="ArgumentNullException">    Thrown when one or more required arguments are
 ///                                             null. </exception>
 /// <param name="phoneNumber">  The phone number. </param>
 /// <param name="countryName">      (Optional) The country. </param>
 /// <returns>   The formatted value. </returns>
 public static string Format(string phoneNumber, string countryName = "")
 {
     if (string.IsNullOrEmpty(phoneNumber))
     {
         throw new ArgumentNullException("phoneNumber");
     }
     return(CountryMetaDataRetriever.InitializeAsync().ContinueWith(task =>
     {
         var countryMetaData = GetCountryMetaData(countryName);
         var formattedPhoneNumber = new PhoneNumber(countryMetaData, phoneNumber).ToString();
         return formattedPhoneNumber;
     }).Result);
 }
Exemplo n.º 3
0
 /// <summary>   Gets country meta data. </summary>
 /// <remarks>   Sander.struijk, 25.02.2014. </remarks>
 /// <param name="countryName">  The country. </param>
 /// <returns>   The country meta data. </returns>
 private static CountryMetaData GetCountryMetaData(string countryName)
 {
     return(string.IsNullOrEmpty(countryName) ? new CountryMetaData() : CountryMetaDataRetriever.GetCountryMetaData(countryName));
 }