/// <summary> /// Writes the current csv record to the stream and clears its content /// </summary> /// <returns>A task that represents the asynchronous operation.</returns> public async Task WriteAsync() { if (_wasPreviousWrite) { await _csvWriter.WriteLineAsync(); } await _csvWriter.WriteValuesAsync(_csvValues); _wasPreviousWrite = true; Array.Fill(_csvValues, null); }
/// <summary> /// Writes the csv dictionary to a CSV target /// </summary> /// <param name="csvWriter">A <see cref="CsvWriter"/></param> /// <returns>A task that represents the asynchronous operation. The value of the TResult // parameter contains the number of key/value pairs written.</returns> public async Task <int> StoreAsync(CsvWriter csvWriter) { if (csvWriter == null) { throw new ArgumentNullException(nameof(csvWriter)); } var c = 0; var wasPreviousWrite = false; foreach (var keyValuePair in _keyValuePairs) { if (wasPreviousWrite) { await csvWriter.WriteLineAsync(); } wasPreviousWrite = true; await csvWriter.WriteValuesAsync(keyValuePair.Key, keyValuePair.Value); c++; } return(c); }
/// <summary> /// Writes a list of values to the CSV streem and closes the current row within the CSV stream. /// </summary> /// <param name="csvWriter">The <see cref="CsvWriter"/></param> /// <param name="values">The list of values to be written.</param> /// <returns>A task that represents the asynchronous write operation.</returns> public static async Task WriteLineValuesAsync(this CsvWriter csvWriter, IEnumerable <string> values) { await csvWriter.WriteValuesAsync(values); await csvWriter.WriteLineAsync(); }
/// <summary> /// Writes a list of values to the CSV streem /// </summary> /// <param name="csvWriter">The <see cref="CsvWriter"/></param> /// <param name="values">The list of values to be written.</param> /// <returns>A task that represents the asynchronous write operation.</returns> public static async Task WriteValuesAsync(this CsvWriter csvWriter, params string[] values) { await csvWriter.WriteValuesAsync((IEnumerable <string>) values); }