private List <Passport> ParsePassports(string input) { string inputString = Helpers.General.GetDataFromInputFileAsString(input); var passportArray = inputString.Split("\r\n\r\n", StringSplitOptions.TrimEntries); var passpordParser = new Regex("(?<key>\\w*):(?<value>.*?)([\\r\\n ]|$)", RegexOptions.Compiled); var parsedPassportArray = new List <Passport>(); foreach (var passportString in passportArray) { var passport = new Passport(); var parsedPassportCollection = passpordParser.Matches(passportString); foreach (Match parsedPassport in parsedPassportCollection) { var key = parsedPassport.Groups["key"].Value.ToString().Trim(); var value = parsedPassport.Groups["value"].Value.ToString().Trim(); var propertyInfo = passport.GetType().GetProperty(key); if (propertyInfo != null) { propertyInfo.SetValue(passport, value, null); } } parsedPassportArray.Add(passport); } return(parsedPassportArray); }