Esempio n. 1
0
 /// <summary>
 /// Read in a single CSV file as an array of objects
 /// </summary>
 /// <typeparam name="T">The type of objects to deserialize from this CSV.</typeparam>
 /// <param name="stream">The stream to read.</param>
 /// <param name="settings">The CSV settings to use when loading this array (Default: CSV)</param>
 /// <returns>An array of objects that were retrieved from the CSV file.</returns>
 public static List <T> LoadArray <T>(StreamReader stream, CSVSettings settings) where T : class, new()
 {
     using (CSVReader cr = new CSVReader(stream, settings))
     {
         return(cr.Deserialize <T>());
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Deserialize a CSV string into a list of typed objects
 /// </summary>
 /// <typeparam name="T">The type of objects to deserialize</typeparam>
 /// <param name="settings">The CSV settings to use when parsing the source (Default: CSV)</param>
 /// <param name="source">The source CSV to deserialize</param>
 /// <returns></returns>
 public static List <T> Deserialize <T>(string source, CSVSettings settings = null) where T : class, new()
 {
     byte[] byteArray = Encoding.UTF8.GetBytes(source);
     using (var stream = new MemoryStream(byteArray))
     {
         using (CSVReader cr = new CSVReader(new StreamReader(stream), settings))
         {
             return(cr.Deserialize <T>());
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Read in a single CSV file as an array of objects
 /// </summary>
 /// <typeparam name="T">The type of objects to deserialize from this CSV.</typeparam>
 /// <param name="stream">The stream to read.</param>
 /// <param name="ignore_dimension_errors">Set to true if you wish to ignore rows that have a different number of columns.</param>
 /// <param name="ignore_bad_columns">Set to true if you wish to ignore column headers that don't match up to object attributes.</param>
 /// <param name="ignore_type_conversion_errors">Set to true if you wish to overlook elements in the CSV array that can't be properly converted.</param>
 /// <param name="delim">The CSV field delimiter character.</param>
 /// <param name="qual">The CSV text qualifier character.</param>
 /// <returns>An array of objects that were retrieved from the CSV file.</returns>
 public static List <T> LoadArray <T>(StreamReader stream, bool ignore_dimension_errors = true, bool ignore_bad_columns = true, bool ignore_type_conversion_errors = true, char delim = CSV.DEFAULT_DELIMITER, char qual = CSV.DEFAULT_QUALIFIER) where T : class, new()
 {
     using (CSVReader cr = new CSVReader(stream, delim, qual)) {
         return(cr.Deserialize <T>(ignore_dimension_errors, ignore_bad_columns, ignore_type_conversion_errors));
     }
 }