public string AddressToString(Person person) { // Stores person.Address for shorter access-name Address address = person.Address; // Gets name as single object. var personAsString = _personFormatter.PersonToString(person); // TODO Assemble address string initialAssembly = $"{personAsString}{n}{address.Address1}{n}"; // Select correct format string midAssembly = selectFormat(address); string finalAssembly = $"{address.Postcode}"; // Object to collect address as a single string including name var addressOutput = $"{initialAssembly}{midAssembly}{finalAssembly}"; return addressOutput; }
public Person stringToPerson(string stringToPersonify) { string[] properties = stringToPersonify.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); Person personOutput = new Person(); var propertyArray = personOutput.GetType().GetProperties(); foreach(var property in propertyArray) { if (property.Name == "Address") { Address address = setSubProperties(properties); property.SetValue(personOutput, address); } else { property.SetValue(personOutput, properties[i]); i++; } } return personOutput; }