Modern CSV (De)Serializer
MIT License
Modern CSV (De)Serializer
This code hasn't seen much production use, please use with caution and report any issues you encounter.
Consult The Wiki for documentation, and Cesil's Github Pages for references.
You may be interested in:
using Cesil;
to your C# fileConfiguration.For<TYourType>()
or Configuration.ForDynamic()
, as appropriate for your use caseCreateReader
, CreateAsyncReader
, CreateWriter
, or CreateAsyncWriter
methods on the configuration.
TextReaders
, Pipes
, and so on.IReader<TRow>
, IAsyncReader<TRow>
, IWriter<TRow>
, or IAsyncWriter<TRow>
interface to read or write your data.Using a convient method:
using Cesil;
// ...
IEnumerable<MyType> rows = CesilUtils.Enumerate<MyType>(/*Some TextReader*/);
In a more explicit, and configurable, way using explicit configuration and options.
using Cesil;
// ...
Options myOptions = /* ... */
IBoundConfiguration<MyType> myConfig = Configuration.For<MyType>(myOptions);
using(TextReader reader = /* ... */)
using(IReader<MyType> csv = myConfig.CreateReader(reader))
{
IEnumerable<MyType> rows = csv.EnumerateAll();
}
For more detail, see Reading.
Using a convient method:
using Cesil;
// ...
IAsyncEnumerable<MyType> rows = CesilUtils.EnumerateAsync<MyType>(/*Some TextReader*/);
In a more explicit, and configurable, way using explicit configuration and options.
using Cesil;
// ...
Options myOptions = /* ... */
IBoundConfiguration<MyType> myConfig = Configuration.For<MyType>(myOptions);
using(TextReader reader = /* ... */)
await using(IAsyncReader<MyType> csv = myConfig.CreateAsyncReader(reader))
{
IAsyncReader<MyType> rows = csv.EnumerateAllAsync();
}
For more detail, see Reading.
Using a convient method:
using Cesil;
// ...
IEnumerable<MyType> myRows = /* ... */
using(TextWriter writer = /* .. */)
{
CesilUtilities.Write(myRows, writer);
}
In a more explicit, and configurable, way using explicit configuration and options.
using Cesil;
// ...
IEnumerable<MyType> myRows = /* ... */
Options myOptions = /* ... */
IBoundConfiguration<MyType> myConfig = Configuration.For<MyType>(myOptions);
using(TextWriter writer = /* ... */)
using(IWriter<MyType> csv = myConfig.CreateWriter(writer))
{
csv.WriteAll(myRows);
}
For more detail, see Writing.
Using a convient method:
using Cesil;
// ...
// IAsyncEnumerable<MyType> will also work
IEnumerable<MyType> myRows = /* ... */
using(TextWriter writer = /* .. */)
{
await CesilUtilities.WriteAsync(myRows, writer);
}
In a more explicit, and configurable, way using explicit configuration and options.
using Cesil;
// ...
// IAsyncEnumerable<MyType> will also work
IEnumerable<MyType> myRows = /* ... */
Options myOptions = /* ... */
IBoundConfiguration<MyType> myConfig = Configuration.For<MyType>(myOptions);
using(TextWriter writer = /* ... */)
await using(IWriter<MyType> csv = myConfig.CreateAsyncWriter(writer))
{
await csv.WriteAllAsync(myRows);
}
For more detail, see Writing.