/// <summary> /// Writes a list of custom csv objects directly to the csv stream and opens a new row. /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="csvTableWriter">The <see cref="CsvTableWriter"/></param> /// <param name="entities">List of csv custom objects</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns>A task that represents the asynchronous write operation.</returns> public static async Task WriteAllAsync <TEntity>(this CsvTableWriter csvTableWriter, IEnumerable <TEntity> entities, CancellationToken cancellationToken = default) { if (entities == null) { throw new ArgumentNullException(nameof(entities)); } foreach (var entity in entities) { cancellationToken.ThrowIfCancellationRequested(); csvTableWriter.SetValues(entity); await csvTableWriter.WriteAsync(); } }
/// <summary> /// Writes values directly to the csv stream and opens a new row. /// </summary> /// <param name="csvTableWriter">The <see cref="CsvTableWriter"/></param> /// <param name="values">List of values</param> /// <returns>A task that represents the asynchronous write operation.</returns> public static async Task WriteAsync(this CsvTableWriter csvTableWriter, IEnumerable <object> values) { if (values == null) { throw new ArgumentNullException(nameof(values)); } int i = 0; foreach (var value in values) { csvTableWriter.SetValue(i, value); i++; } await csvTableWriter.WriteAsync(); }
/// <summary> /// Writes a custom csv object directly to the csv stream and opens a new row. /// </summary> /// <typeparam name="TEntity">The custom csv object type</typeparam> /// <param name="csvTableWriter">The <see cref="CsvTableWriter"/></param> /// <param name="entity">The csv object</param> /// <returns>A task that represents the asynchronous write operation.</returns> public static async Task WriteAsync <TEntity>(this CsvTableWriter csvTableWriter, TEntity entity) { csvTableWriter.SetValues(entity); await csvTableWriter.WriteAsync(); }
/// <summary> /// Writes values directly to the csv stream and opens a new row. /// </summary> /// <param name="csvTableWriter">The <see cref="CsvTableWriter"/></param> /// <param name="values">List of values</param> /// <returns>A task that represents the asynchronous write operation.</returns> public static async Task WriteAsync(this CsvTableWriter csvTableWriter, params object[] values) { await csvTableWriter.WriteAsync((IEnumerable <object>) values); }