ConvertCsvToList

I create a gist for a helper funtion I used recently to convert a CSV file’s contents to a typed list:

private IList<T> ConvertCsvToList<T>(IList<string> csv, string[] header) {
    var list = new List<T>();
    foreach (var row in csv) {
        var columns = row.Split(',');
        T obj = (T)Activator.CreateInstance(typeof(T));
 
        for (int i = 0; i < columns.Length; i++) {
            var h = Regex.Match(header[i].Replace("@", "_"), 
                @"(?<="")(?:\\.|[^""\\])*(?="")").Value;
            var c = Regex.Match(columns[i], 
                @"(?<="")(?:\\.|[^""\\])*(?="")").Value;
            var prop = typeof(Em.Schools.Data.Domain.Match).GetProperty(h);
            if (prop.PropertyType == typeof(int)) {
                prop.SetValue(obj, Convert.ToInt32(c), null);
            } else {
                prop.SetValue(obj, c, null);
            }
        }
 
        list.Add(obj);
    }
 
    return list;
}