Lightweight extension methods around CsvHelper that make it easy to read and write CSV files with synchronous or asynchronous APIs.
This package is intended as a small utility library you can reuse across projects, instead of rewriting boilerplate around CsvHelper.
-
Read CSV (sync/async)
CsvFile.Read<T>(filePath)→IEnumerable<T>CsvFile.ReadAsync<T>(filePath)→IAsyncEnumerable<T>
-
Write CSV (sync/async)
CsvFile.Write<T>(filePath, items)CsvFile.WriteAsync<T>(filePath, items)
-
Built on CsvHelper with sensible defaults (
CultureInfo.InvariantCulture). -
Optional
CsvConfigurationparameter for full control.
dotnet add package ComputerCodeBlue.CsvOr reference the project directly in your solution.
public class Person
{
public string FirstName { get; set; } = default!;
public string LastName { get; set; } = default!;
public int Age { get; set; }
}using ComputerCodeBlue.Csv;
var people = CsvFile.Read<Person>("people.csv");
foreach (var person in people)
{
Console.WriteLine($"{person.FirstName} {person.LastName} ({person.Age})");
}using ComputerCodeBlue.Csv;
await foreach (var person in CsvFile.ReadAsync<Person>("people.csv"))
{
Console.WriteLine($"{person.FirstName} {person.LastName} ({person.Age})");
}using ComputerCodeBlue.Csv;
var people = new List<Person>
{
new() { FirstName = "Alice", LastName = "Smith", Age = 30 },
new() { FirstName = "Bob", LastName = "Johnson", Age = 42 }
};
CsvFile.Write("people.csv", people);using ComputerCodeBlue.Csv;
await CsvFile.WriteAsync("people.csv", people);IEnumerable<T> Read<T>(string filePath, CsvConfiguration? config = null);
IAsyncEnumerable<T> ReadAsync<T>(
string filePath,
CsvConfiguration? config = null,
CancellationToken ct = default);
void Write<T>(
string filePath,
IEnumerable<T> items,
CsvConfiguration? config = null);
Task WriteAsync<T>(
string filePath,
IEnumerable<T> items,
CsvConfiguration? config = null,
CancellationToken ct = default);MIT © Computer Code Blue LLC