AWise.SepCsvSourceGenerator 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package AWise.SepCsvSourceGenerator --version 0.1.0
                    
NuGet\Install-Package AWise.SepCsvSourceGenerator -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AWise.SepCsvSourceGenerator" Version="0.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AWise.SepCsvSourceGenerator" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="AWise.SepCsvSourceGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AWise.SepCsvSourceGenerator --version 0.1.0
                    
#r "nuget: AWise.SepCsvSourceGenerator, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AWise.SepCsvSourceGenerator@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AWise.SepCsvSourceGenerator&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=AWise.SepCsvSourceGenerator&version=0.1.0
                    
Install as a Cake Tool

A source generator for Sep CSV parsing

This is a C# source generator for generating strongly typed parsing of CSV files using the excellent Sep CSV library.

Usage

First, add a reference to the Nuget packages:

dotnet add package Sep
dotnet add package AWise.SepCsvSourceGenerator

To use the source generator, define a partial class and a partial static method with the [GenerateCsvParser] attribute. The source generator will generate the implementation of this method.

Here is an example:

using nietras.SeparatedValues;
using AWise.SepCsvSourceGenerator;

public partial class MyRecord
{
    [CsvHeaderName("Name")]
    public required string Name { get; set; }

    [CsvHeaderName("Date")]
    [CsvDateFormat("yyyy-MM-dd")]
    public DateTime Date { get; set; }

    [GenerateCsvParser]
    public static partial IEnumerable<MyRecord> Parse(SepReader reader, CancellationToken ct);
}

You can then use the generated Parse method to parse a CSV file:

const string CSV_CONTENT = "Name,Date\nJohn,2023-01-15\nJane,2023-02-20";

using var reader = Sep.Reader().FromText(CSV_CONTENT);
var records = MyRecord.Parse(reader, CancellationToken.None);

foreach (var record in records)
{
    Console.WriteLine($"Name: {record.Name}, Date: {record.Date.ToShortDateString()}");
}

If a property is is init or required, an exception will be thrown if the CSV file does not have the column. If the property has set, the generated parser will only set the property if the column exists in the CSV file.

The only types that are supported for parsing are types that implement ISpanParsable.

DateTime, DateTimeOffset, DateOnly, and TimeOnly are given special treatment. They are parsed with their respective ParseExact methods using CultureInfo.InvariantCulture. Specify the date-time format using the CsvDateFormat attribute.

Supported attributes

The following attributes are supported on the properties of the partial class:

  • [CsvHeaderName("...")]: Specifies the name of the column in the CSV file.
  • [CsvDateFormat("...")]: Specifies the date format for DateTime, DateTimeOffset, DateOnly, and TimeOnly properties.

Async parsing

The source generator also supports generating asynchronous parsing methods. To do this, define a method that returns an IAsyncEnumerable<T>:

[GenerateCsvParser]
public static partial IAsyncEnumerable<MyRecord> ParseAsync(SepReader reader, CancellationToken ct);
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.1-preview003 157 11/1/2025
0.3.0 198 8/10/2025
0.2.1 376 7/20/2025
0.2.0 359 7/20/2025
0.1.0 123 7/19/2025
0.1.0-preview006 124 7/19/2025
0.1.0-preview005 208 7/13/2025
0.1.0-preview003 160 7/13/2025
0.1.0-preview001 157 7/13/2025