/// <summary> Returns a string that represents the current object. </summary> /// <remarks> Sander.struijk, 26.02.2014. </remarks> /// <returns> A string that represents the current object. </returns> public override string ToString() { var countryCode = FormatCountryCode(CountryCode); var formattedPhoneNumber = NumberGroups.Any() ? AggregateNumberGroups(countryCode) : DefaultFormatting(countryCode); return(formattedPhoneNumber.Trim()); }
/// <summary> Initializes the phone number format number groups. </summary> /// <remarks> Sander.struijk, 26.02.2014. </remarks> /// <param name="countryMetaData"> Information describing the country meta data. </param> private void InitializePhoneNumberFormatNumberGroups(CountryMetaData countryMetaData) { var startIndex = 0; foreach (var groupCount in countryMetaData.PhoneNumberFormat) { var numberGroup = Number.Substring(startIndex, groupCount); startIndex += groupCount; NumberGroups.Add(numberGroup); } }
/// <summary> Aggregate number groups. </summary> /// <remarks> Sander.struijk, 26.02.2014. </remarks> /// <param name="countryCode"> The country code. </param> /// <returns> The phone number. </returns> private string AggregateNumberGroups(string countryCode) { return(NumberGroups.Aggregate(countryCode, (current, next) => string.Format("{0} {1}", current, next))); }