Cesil

Modern CSV (De)Serializer

MIT License

Stars
66

Cesil

Modern CSV (De)Serializer

PRE-RELEASE

This code hasn't seen much production use, please use with caution and report any issues you encounter.

Documentation

Consult The Wiki for documentation, and Cesil's Github Pages for references.

You may be interested in:

Quick Start

  1. Install the latest Cesil off of Nuget.
  2. Add using Cesil; to your C# file
  3. Create a configuration (with default Options) with either Configuration.For<TYourType>() or Configuration.ForDynamic(), as appropriate for your use case
  4. Create a reader or writer using one of the CreateReader, CreateAsyncReader, CreateWriter, or CreateAsyncWriter methods on the configuration.
    • Each of these methods has a number of overloads, supporting using TextReaders, Pipes, and so on.
  5. Use the methods on the IReader<TRow>, IAsyncReader<TRow>, IWriter<TRow>, or IAsyncWriter<TRow> interface to read or write your data.

Example: Reading Synchronously

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.

Example: Reading Asynchronously

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.

Example: Writing Synchronously

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.

Example: Writing Asynchronously

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.

Badges
Extracted from project README
Run Tests (Debug) Line Coverage Branch Coverage