internal static Contact GetContact (ABPerson person) { Contact contact = new Contact (person) { DisplayName = person.ToString(), Prefix = person.Prefix, FirstName = person.FirstName, MiddleName = person.MiddleName, LastName = person.LastName, Suffix = person.Suffix, Nickname = person.Nickname }; contact.Notes = (person.Note != null) ? new [] { new Note { Contents = person.Note } } : new Note[0]; contact.Emails = person.GetEmails().Select (e => new Email { Address = e.Value, Type = GetEmailType (e.Label), Label = (e.Label != null) ? GetLabel (e.Label) : GetLabel (ABLabel.Other) }); contact.Phones = person.GetPhones().Select (p => new Phone { Number = p.Value, Type = GetPhoneType (p.Label), Label = (p.Label != null) ? GetLabel (p.Label) : GetLabel (ABLabel.Other) }); Organization[] orgs; if (person.Organization != null) { orgs = new Organization[1]; orgs[0] = new Organization { Name = person.Organization, ContactTitle = person.JobTitle, Type = OrganizationType.Work, Label = GetLabel (ABLabel.Work) }; } else orgs = new Organization[0]; contact.Organizations = orgs; contact.InstantMessagingAccounts = person.GetInstantMessages().Select (ima => new InstantMessagingAccount() { Service = GetImService ((NSString)ima.Value[ABPersonInstantMessageKey.Service]), ServiceLabel = (NSString)ima.Value[ABPersonInstantMessageKey.Service], Account = (NSString)ima.Value[ABPersonInstantMessageKey.Username] }); contact.Addresses = person.GetAddresses().Select (a => new Address() { Type = GetAddressType (a.Label), Label = (a.Label != null) ? GetLabel (a.Label) : GetLabel (ABLabel.Other), StreetAddress = (NSString)a.Value[ABPersonAddressKey.Street], City = (NSString)a.Value[ABPersonAddressKey.City], Region = (NSString)a.Value[ABPersonAddressKey.State], Country = (NSString)a.Value[ABPersonAddressKey.Country], PostalCode = (NSString)a.Value[ABPersonAddressKey.Zip] }); contact.Websites = person.GetUrls().Select (url => new Website { Address = url.Value }); contact.Relationships = person.GetRelatedNames().Select (p => new Relationship { Name = p.Value, Type = GetRelationType (p.Label) }); return contact; }
internal static Organization GetOrganization (ICursor c, Resources resources) { Organization o = new Organization(); o.Name = c.GetString (OrganizationData.Company); o.ContactTitle = c.GetString (OrganizationData.Title); OrganizationDataKind d = (OrganizationDataKind) c.GetInt (c.GetColumnIndex (CommonColumns.Type)); o.Type = d.ToOrganizationType(); o.Label = (d != OrganizationDataKind.Custom) ? OrganizationData.GetTypeLabel (resources, d, String.Empty) : c.GetString (CommonColumns.Label); return o; }