Exemple #1
0
        /// <summary>
        /// This method tries to load all values from given file using given
        /// settings.
        /// </summary>
        /// <remarks>
        /// The settings parameter describes how the data within given file should be
        /// processed. For example, users may define the expected culture, the expected
        /// file encoding, which separator is used and so on.
        /// </remarks>
        /// <param name="filename">
        /// The fully qualified path of the input file.
        /// </param>
        /// <param name="settings">
        /// The settings to be used to process file data.
        /// </param>
        /// <returns>
        /// A list of classes of  <typeparamref name="TInstance"/>.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// This exception is thrown in case of an invalid file name.
        /// </exception>
        /// <exception cref="FileNotFoundException">
        /// This exception is thrown in case of a file with given name does not
        /// exist.
        /// </exception>
        public static IEnumerable <TInstance> Load(String filename, CsvSettings settings)
        {
            if (String.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentException("The filename should not be empty.", nameof(filename));
            }

            if (!File.Exists(filename))
            {
                throw new FileNotFoundException($"File {filename} could not be found.");
            }

            using (Stream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                return(CsvImporter <TInstance> .Load(stream, settings));
            }
        }
Exemple #2
0
 /// <summary>
 /// This method tries to load all values from given stream.
 /// </summary>
 /// <remarks>
 /// This method performes loading of data with default settings. Using
 /// default settings means that the header is processed, but only if one
 /// exist. Further, The information for header processing is taken from
 /// column attributes or from property names.
 /// </remarks>
 /// <param name="stream">
 /// The stream to read data from.
 /// </param>
 /// <returns>
 /// A list of classes of  <typeparamref name="TInstance"/>.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// This exception is thrown in case of given stream is invalid.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// This exception is thrown in case of given stream does not have read access.
 /// </exception>
 public static IEnumerable <TInstance> Load(Stream stream)
 {
     return(CsvImporter <TInstance> .Load(stream, new CsvSettings()));
 }
Exemple #3
0
 /// <summary>
 /// This method tries to load all values from given file.
 /// </summary>
 /// <remarks>
 /// This method performes loading of data with default settings. Using
 /// default settings means that the header is processed, but only if one
 /// exist. Further, the information for header processing is taken from
 /// column attributes or from property names.
 /// </remarks>
 /// <param name="filename">
 /// The fully qualified path of the input file.
 /// </param>
 /// <returns>
 /// A list of classes of <typeparamref name="TInstance"/>.
 /// </returns>
 /// <exception cref="ArgumentException">
 /// This exception is thrown in case of an invalid file name.
 /// </exception>
 /// <exception cref="FileNotFoundException">
 /// This exception is thrown in case of a file with given name does not
 /// exist.
 /// </exception>
 public static IEnumerable <TInstance> Load(String filename)
 {
     return(CsvImporter <TInstance> .Load(filename, new CsvSettings()));
 }