/// <summary> /// Creates a new CsvDataReader asynchronously. /// </summary> /// <param name="reader">The TextReader for the delimited data.</param> /// <param name="options">The options to configure the reader, or null to use the default options.</param> /// <returns>A task representing the asynchronous creation of a CsvDataReader instance.</returns> public static async Task <CsvDataReader> CreateAsync(TextReader reader, CsvDataReaderOptions?options = null) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } var csv = new CsvDataReader(reader, options); await csv.InitializeAsync(options?.Schema); return(csv); }
/// <summary> /// Creates a new CsvDataReader asynchronously. /// </summary> /// <param name="filename">The name of a file containing CSV data.</param> /// <param name="options">The options to configure the reader, or null to use the default options.</param> /// <returns>A task representing the asynchronous creation of a CsvDataReader instance.</returns> public static async Task <CsvDataReader> CreateAsync(string filename, CsvDataReaderOptions?options = null) { if (filename == null) { throw new ArgumentNullException(nameof(filename)); } // TextReader must be owned when we open it. if (options?.OwnsReader == false) { throw new CsvConfigurationException(); } var reader = File.OpenText(filename); var csv = new CsvDataReader(reader, options); await csv.InitializeAsync(options?.Schema); return(csv); }