/// <summary> /// /// </summary> /// <param name="contactEmailList"> /// A <see cref="ContactEmail[]"/> /// </param> /// <returns> /// A <see cref="ABMultiValue<System.String>"/> /// </returns> private ABMultiValue<string> ConvertContactEmailsToNative(ContactEmail[] contactEmailList) { ABMutableStringMultiValue multableMultilabel = new ABMutableStringMultiValue(); if(contactEmailList!=null) { foreach(ContactEmail contactEmail in contactEmailList) { NSString label = ABLabel.Other; // default is "Other" if(contactEmail.Type == DispositionType.HomeOffice) { label = ABLabel.Home; } else if(contactEmail.Type == DispositionType.Work) { label = ABLabel.Work; } // Following data not provided on native API. //<< contactEmail.CommonName //<< contactEmail.Firstname //<< contactEmail.IsPrimary //<< contactEmail.Surname multableMultilabel.Add(contactEmail.Address, label); } } return multableMultilabel; }
/// <summary> /// /// </summary> /// <param name="person"> /// A <see cref="ABPerson"/> /// </param> /// <returns> /// A <see cref="ContactEmail[]"/> /// </returns> private ContactEmail[] GetContactEmails(ABPerson person) { List<ContactEmail> contactEmailList = new List<ContactEmail>(); if(person != null) { ABMultiValue<string> emails = person.GetEmails(); if(emails!=null) { IEnumerator enumerator = emails.GetEnumerator(); while(enumerator.MoveNext()){ object currentEmail = enumerator.Current; string label = ((ABMultiValueEntry<string>)currentEmail).Label; string email = ((ABMultiValueEntry<string>)currentEmail).Value; ContactEmail contactEmail = new ContactEmail(); contactEmail.Address = email; // Following data not provided. //contactEmail.CommonName = //contactEmail.Firstname = //contactEmail.IsPrimary = //contactEmail.Surname = if(label == ABLabel.Home) { contactEmail.Type = DispositionType.HomeOffice; } else if(label == ABLabel.Work) { contactEmail.Type = DispositionType.Work; } else { contactEmail.Type = DispositionType.Other; } contactEmailList.Add(contactEmail); } } } return contactEmailList.ToArray(); }
private ContactEmail[] GetContactEmailArray(Windows.ApplicationModel.Contacts.Contact contact) { var emailList = new List<ContactEmail>(); foreach (var email in contact.Emails.Where(email => !String.IsNullOrWhiteSpace(email.Address))) { var conEmail = new ContactEmail { Address = email.Address }; switch (email.Kind) { case ContactEmailKind.Personal: conEmail.Type = DispositionType.Personal; break; case ContactEmailKind.Work: conEmail.Type = DispositionType.Work; break; default: conEmail.Type = DispositionType.Other; break; } emailList.Add(conEmail); } return emailList.ToArray(); }