/// <summary> /// Convert vCard to string. /// </summary> /// <returns>Formatted vCard string.</returns> public override string ToString() { var sb = new StringBuilder(); string characterSetModifier = _characterSet.Length > 0 ? string.Format(";CHARSET={0}", _characterSet) : string.Empty; sb.Append("BEGIN:VCARD\r\n"); if (_formattedName != null) { sb.Append(string.Concat("FN:", PropertyValueEncoder.GetEncodedPropertyValue(_formattedName, false), "\r\n")); } sb.Append(string.Concat("N", characterSetModifier, ":", PropertyValueEncoder.GetEncodedPropertyValue(_lastName, false), ";")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_firstName, false), ";")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_middleName, false), ";")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_namePrefix, false), ";")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_nameSuffix, false), "\r\n")); if (_birthDate != DateTime.MinValue) { sb.Append(string.Concat("BDAY:", PropertyValueEncoder.GetEncodedPropertyValue(_birthDate.ToString("yyyyMMdd"), false), "\r\n")); } foreach (var da in _addresses) { da.CharacterSet = CharacterSet; sb.Append(da); } foreach (var phone in _phoneNumbers) { sb.Append(phone); } foreach (var email in _emailAddresses) { if (!string.IsNullOrEmpty(email)) { sb.Append(string.Concat("EMAIL", characterSetModifier, "; INTERNET:", PropertyValueEncoder.GetEncodedPropertyValue(email, false), "\r\n")); } } sb.Append(string.Concat("TITLE", characterSetModifier, ";ENCODING=QUOTED-PRINTABLE", ":", PropertyValueEncoder.GetEncodedPropertyValue(_title, true), "\r\n")); sb.Append(string.Concat("ROLE", characterSetModifier, ":", PropertyValueEncoder.GetEncodedPropertyValue(_role, false), "\r\n")); sb.Append(string.Concat("ORG", characterSetModifier, ":", PropertyValueEncoder.GetEncodedPropertyValue(_organization, false), "\r\n")); if (!string.IsNullOrEmpty(_note)) { sb.Append(string.Concat("NOTE", characterSetModifier, ";ENCODING=QUOTED-PRINTABLE", ":", PropertyValueEncoder.GetEncodedPropertyValue(_note, true), "\r\n")); } if (!string.IsNullOrEmpty(_url)) { sb.Append(string.Concat("URL; WORK", characterSetModifier, ":", PropertyValueEncoder.GetEncodedPropertyValue(_url, false), "\r\n")); } sb.Append("END:VCARD\r\n"); return(sb.ToString()); }
/// <summary> /// Converts phone number to string. /// </summary> /// <returns>Phone number in string format.</returns> public override string ToString() { var sb = new StringBuilder(); sb.Append(string.Concat("TEL;", PhoneNumberType == PhoneNumberTypes.FAX ? "WORK;" : string.Empty, Enum.GetName(typeof(PhoneNumberTypes), PhoneNumberType), ":")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_number, false), "\r\n")); return(sb.ToString()); }
/// <summary> /// Convert delivery address to a string. /// </summary> /// <returns>Resulting string.</returns> public override string ToString() { var sb = new StringBuilder(); var characterSetModifier = _characterSet.Length > 0 ? string.Format(";CHARSET={0}", _characterSet) : string.Empty; sb.Append(string.Concat("ADR", characterSetModifier, ";", "ENCODING=QUOTED-PRINTABLE;", Enum.GetName(typeof(AddressTypes), _deliveryAddressType), ":")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_postOfficeAddress, true), ";")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_extendedAddress, true), ";")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_street, true), ";")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_locality, true), ";")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_region, true), ";")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_postalCode, true), ";")); sb.Append(string.Concat(PropertyValueEncoder.GetEncodedPropertyValue(_country, true), "\r\n")); return(sb.ToString()); }