Dameng.SepEx.Generator
0.2.4
See the version list below for details.
dotnet add package Dameng.SepEx.Generator --version 0.2.4
NuGet\Install-Package Dameng.SepEx.Generator -Version 0.2.4
<PackageReference Include="Dameng.SepEx.Generator" Version="0.2.4"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Dameng.SepEx.Generator" Version="0.2.4" />
<PackageReference Include="Dameng.SepEx.Generator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Dameng.SepEx.Generator --version 0.2.4
#r "nuget: Dameng.SepEx.Generator, 0.2.4"
#:package Dameng.SepEx.Generator@0.2.4
#addin nuget:?package=Dameng.SepEx.Generator&version=0.2.4
#tool nuget:?package=Dameng.SepEx.Generator&version=0.2.4
Dameng.SepEx
A high-performance source generator for working with separated values (CSV/TSV) files in C#. This library extends the excellent Sep library by providing compile-time code generation for strongly-typed reading and writing of CSV data.
Features
- Source Generator: Automatically generates type-safe CSV readers and writers at compile time
- High Performance: Built on top of the fast Sep library
- Attribute-Based Configuration: Use attributes to configure column mapping, formatting, and behavior
- Flexible Column Mapping: Support for column names, indexes, default values, and formatting
- Type Safety: Compile-time type checking and IntelliSense support
Installation
Install the NuGet packages:
dotnet add package Dameng.SepEx
dotnet add package Dameng.SepEx.Generator
Quick Start
- Define your data model with attributes:
[GenSepParsable]
public partial class Person
{
[SepColumnIndex(0)]
public string Name { get; set; }
[SepColumnName("Age")]
public int Age { get; set; }
[SepDefaultValue("Unknown")]
public string City { get; set; }
[SepIgnore]
public string InternalId { get; set; }
}
- Read and write CSV data:
// Reading
using var reader = Sep.Reader().FromFile("people.csv");
foreach (var person in reader.GetRecords<Person>())
{
Console.WriteLine($"{person.Name} is {person.Age} years old");
}
// Writing
var people = new List<Person> { /* ... */ };
using var writer = Sep.Writer().ToFile("output.csv");
writer.WriteRecord(people);
External Data Model
- Generate type info using attributes:
[GenSepTypeInfo<Person>()]
public partial class PersonTypeInfo;
- Read and write CSV data:
// Reading
using var reader = Sep.Reader().FromFile("people.csv");
foreach (var person in reader.GetRecords<Person>(PersonTypeInfo.Person))
{
Console.WriteLine($"{person.Name} is {person.Age} years old");
}
// Writing
var people = new List<Person> { /* ... */ };
using var writer = Sep.Writer().ToFile("output.csv");
writer.WriteRecord(people, PersonTypeInfo.Person);
Available Attributes
[GenSepTypeInfo<T>()]
: Generate type info for the specified type[SepColumnName(string name)]
: Specify column name[SepColumnIndex(int index)]
: Specify column index for reading/writing order[SepDefaultValue(object value)]
: Set default value when column is missing[SepColumnIgnore]
: Ignore property/field during CSV operations[SepColumnFormat(string format)]
: Specify format for writing values
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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.