AWise.SepCsvSourceGenerator
0.1.0
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
<PackageReference Include="AWise.SepCsvSourceGenerator" Version="0.1.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="AWise.SepCsvSourceGenerator" Version="0.1.0" />
<PackageReference Include="AWise.SepCsvSourceGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add AWise.SepCsvSourceGenerator --version 0.1.0
#r "nuget: AWise.SepCsvSourceGenerator, 0.1.0"
#:package AWise.SepCsvSourceGenerator@0.1.0
#addin nuget:?package=AWise.SepCsvSourceGenerator&version=0.1.0
#tool nuget:?package=AWise.SepCsvSourceGenerator&version=0.1.0
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 forDateTime,DateTimeOffset,DateOnly, andTimeOnlyproperties.
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);
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 |