//The validation logic from above private static ValidationResult ValidatePerson(Person personFromFile, string line) { var validationResult = new ValidationResult(); if (!Regex.IsMatch(personFromFile.FirstName, @"^[a-zA-z]+$")) { validationResult.AddParseError(new ParseError("FirstName can only contain alpha characters", line)); } if (!Regex.IsMatch(personFromFile.LastName, @"^[a-zA-z]+$")) { validationResult.AddParseError(new ParseError("LastName can only contain alpha characters", line)); } return validationResult; }
private static void AddValidObjectOrParseErrorToResults(ValidationResult validationResult, ParseResult<Person> parseResult, Person personToAdd, string line) { if (validationResult.IsValid) { parseResult.AddParsedRecordToCollection(personToAdd); } else { foreach (var errorMessage in validationResult.GetErrorMessages()) { parseResult.AddParsedErrorToCollection(errorMessage, line); } } }