static Contact ToContact(ContactsRecord contactsRecord) { var record = contactsRecord.GetChildRecord(TizenContact.Name, 0); var phones = new List <ContactPhone>(); var phonesCount = contactsRecord.GetChildRecordCount(TizenContact.Number); for (var i = 0; i < phonesCount; i++) { var nameRecord = contactsRecord.GetChildRecord(TizenContact.Number, i); var number = nameRecord.Get <string>(TizenNumber.NumberData); phones.Add(new ContactPhone(number)); } var emails = new List <ContactEmail>(); var emailCount = contactsRecord.GetChildRecordCount(TizenContact.Email); for (var i = 0; i < emailCount; i++) { var emailRecord = contactsRecord.GetChildRecord(TizenContact.Email, i); var addr = emailRecord.Get <string>(TizenEmail.Address); emails.Add(new ContactEmail(addr)); } return(new Contact( (record?.Get <int>(TizenName.ContactId))?.ToString(), record?.Get <string>(TizenName.Prefix), record?.Get <string>(TizenName.First), record?.Get <string>(TizenName.Addition), record?.Get <string>(TizenName.Last), record?.Get <string>(TizenName.Suffix), phones, emails)); }
private static Contact ContactFromContactsRecord(ContactsRecord contactsRecord) { var contact = new Contact(); if (contactsRecord.GetChildRecordCount(TizenContact.Name) > 0) { var recordName = contactsRecord.GetChildRecord(TizenContact.Name, 0); contact.HonorificNamePrefix = recordName.Get <string>(TizenName.Prefix) ?? string.Empty; contact.FirstName = recordName.Get <string>(TizenName.First) ?? string.Empty; contact.MiddleName = recordName.Get <string>(TizenName.Addition) ?? string.Empty; contact.LastName = recordName.Get <string>(TizenName.Last) ?? string.Empty; contact.HonorificNameSuffix = recordName.Get <string>(TizenName.Suffix) ?? string.Empty; contact.YomiGivenName = recordName.Get <string>(TizenName.PhoneticFirst) ?? string.Empty; contact.YomiFamilyName = recordName.Get <string>(TizenName.PhoneticLast) ?? string.Empty; } var emailCount = contactsRecord.GetChildRecordCount(TizenContact.Email); for (var mailId = 0; mailId < emailCount; mailId++) { var emailRecord = contactsRecord.GetChildRecord(TizenContact.Email, mailId); var address = emailRecord.Get <string>(TizenEmail.Address); var type = (TizenEmail.Types)emailRecord.Get <int>(TizenEmail.Type); contact.Emails.Add(new ContactEmail() { Address = address, Kind = GetContactEmailKind(type) }); } var phoneCount = contactsRecord.GetChildRecordCount(TizenContact.Number); for (var phoneId = 0; phoneId < phoneCount; phoneId++) { var phoneRecord = contactsRecord.GetChildRecord(TizenContact.Number, phoneId); var number = phoneRecord.Get <string>(TizenNumber.NumberData); var type = (TizenNumber.Types)phoneRecord.Get <int>(TizenNumber.Type); contact.Phones.Add(new ContactPhone() { Number = number, Kind = GetContactPhoneKind(type) }); } var addressCount = contactsRecord.GetChildRecordCount(TizenContact.Address); for (var addressId = 0; addressId < addressCount; addressId++) { var addressRecord = contactsRecord.GetChildRecord(TizenContact.Address, addressId); var country = addressRecord.Get <string>(TizenAddress.Country); var locality = addressRecord.Get <string>(TizenAddress.Locality); var street = addressRecord.Get <string>(TizenAddress.Street); var region = addressRecord.Get <string>(TizenAddress.Region); var postalCode = addressRecord.Get <string>(TizenAddress.PostalCode); var type = (TizenAddress.Types)addressRecord.Get <int>(TizenAddress.Type); contact.Addresses.Add(new ContactAddress() { Country = country ?? string.Empty, Locality = locality ?? string.Empty, PostalCode = postalCode ?? string.Empty, Region = region ?? string.Empty, StreetAddress = street ?? string.Empty, Kind = GetContactAddressKind(type) }); } if (contactsRecord.GetChildRecordCount(TizenContact.Note) > 0) { contact.Notes = contactsRecord .GetChildRecord(TizenContact.Note, 0)? .Get <string>(TizenNote.Contents) ?? string.Empty; } if (contactsRecord.GetChildRecordCount(TizenContact.Nickname) > 0) { contact.Nickname = contactsRecord .GetChildRecord(TizenContact.Nickname, 0)? .Get <string>(TizenNickname.Name) ?? string.Empty; } return(contact); }