Regira Office.Csv provides async CSV read and write via CsvHelper, with both generic (typed) and non-generic (dictionary) modes.
| Project | Package | Backend |
|---|---|---|
Common.Office |
(transitive) | Shared abstractions |
Csv.CsvHelper |
Regira.Office.Csv.CsvHelper |
CsvHelper v33 |
<PackageReference Include="Regira.Office.Csv.CsvHelper" Version="6.*" />
```csharp no-compile // Non-generic — rows as Dictionary<string, object> ICsvService csv = new CsvManager(); var rows = await csv.Read(csvString);
// Generic — rows mapped to a POCO
ICsvService
## ICsvService / ICsvService\<T\>
```csharp no-compile
// Read
Task<List<T>> Read(string input, CsvOptions? options = null, CancellationToken cancellationToken = default);
Task<List<T>> Read(IBinaryFile input, CsvOptions? options = null, CancellationToken cancellationToken = default);
// Write
Task<string> Write(IEnumerable<T> items, CsvOptions? options = null, CancellationToken cancellationToken = default);
Task<IMemoryFile> WriteFile(IEnumerable<T> items, CsvOptions? options = null, CancellationToken cancellationToken = default);
ICsvService is ICsvService<IDictionary<string, object>>.
| Property | Type | Default | Description |
|---|---|---|---|
Delimiter |
string |
"," |
Column separator |
Culture |
CultureInfo |
en-US |
Number / date formatting |
| Member | Type | Default | Description |
|---|---|---|---|
IgnoreBadData |
bool (public field) |
false |
Skip malformed rows instead of throwing |
PreserveWhitespace |
bool (public field) |
false |
Keep leading/trailing whitespace in cell values |
IgnoreBadDataandPreserveWhitespaceare only honored when theCsvHelperOptionsinstance is passed to theCsvManagerconstructor. On the per-calloptionsparameter onlyDelimiterandCultureare read — the two flags are silently ignored there.
```csharp no-compile
// Flags must go through the constructor:
var csv = new CsvManager
## Notes
- First row is always treated as the header.
- The non-generic `CsvManager` reads each row into a `Dictionary<string, object>`.
- For typed `CsvManager<T>`, column names must match property names (or use CsvHelper `[Name]` attributes on the POCO).
- `WriteFile` returns an `IMemoryFile` with `ContentType = "text/csv"`.
## Examples
```csharp no-compile
// Read from uploaded file
var csvFile = formFile.ToNamedFile().ToBinaryFile();
var rows = await new CsvManager().Read(csvFile);
// Read typed with semicolon delimiter
var products = await new CsvManager<Product>()
.Read(csvString, new CsvHelperOptions { Delimiter = ";" });
// Write typed
IMemoryFile file = await new CsvManager<Order>()
.WriteFile(orders, new CsvOptions { Delimiter = "\t" });
// Write non-generic from a list of dictionaries
string csv = await new CsvManager().Write(rows);