I am parsing CSV files to lists of objects with strongly-typed properties. This involves parsing each string value from the file to an IConvertible
type (
How about constructing a regular expression for each type and applying it to the string before calling Parse? You'd have to build the regular expression such that if the string doesn't match, it wouldn't parse. This would be a little slower if the string parses since you'd have to do the regex test, but it would be way faster if it doesn't parse.
You could put the regex strings in a Dictionary
, which would make determining which regex string to use simple.