private bool ReadContact(string line, List <Column> columns, out Contact contact) { if (string.IsNullOrEmpty(line)) { contact = default; return(false); } string[] values = line.Split(new[] { seperator }, StringSplitOptions.None); if (values.Length != columns.Count) { Console.WriteLine(string.Format("Contact line does not contain appropriate number of columns: {0}", line)); contact = default; return(false); } int? id = new Nullable <int>(); string first = null; string last = null; string street = null; string city = null; string state = null; string zip = null; for (int i = 0; i < values.Length; i++) { switch (columns[i].ColumnName) { case "id": if (!string.IsNullOrEmpty(values[i]) && !string.IsNullOrEmpty(values[i].Trim())) { id = int.Parse(values[i]); break; } break; case "firstname": first = values[i]; break; case "lastname": last = values[i]; break; case "streetaddress": street = values[i]; break; case "city": city = values[i]; break; case "state": state = values[i]; break; case "postalcode": zip = values[i]; break; default: throw new InvalidOperationException("Unknown column name: " + columns[i].ColumnName); } } contact = Contact.Create(first, last, street, city, state, zip); if (id.HasValue) { contact = Contact.CreateWithId(id.Value, contact); } return(true); }