示例#1
0
        //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;
        }
示例#2
0
 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);
         }
     }
 }