static IReadOnlyCollection <string> FormatAddress(ProviderContactAddress address) { var parts = new List <string>() { address.SAON?.Description, address.PAON?.Description, address.StreetDescription, address.Locality }; if (address.Items != null) { parts.AddRange(address.Items); } parts.Add(address.PostCode); return(parts.Where(p => !string.IsNullOrEmpty(p)).ToList()); }
static (string AddressLine1, string AddressLine2) NormalizeAddress(ProviderContactAddress address) { if (address == null) { return(null, null); } var parts = new[] { address?.SAON?.Description, address?.PAON?.Description, address?.StreetDescription }.Where(part => !string.IsNullOrWhiteSpace(part)).ToArray(); // Join all parts except the last into a single line and make that line 1 // then the final part is line 2. var line1 = string.Join(" ", parts.SkipLast(1)); var line2 = parts.Skip(1).LastOrDefault(); return(line1, line2); }