CsvSwan 1.0.1

CsvSwan is a simple and fast CSV reader.

Install-Package CsvSwan -Version 1.0.1
dotnet add package CsvSwan --version 1.0.1
<PackageReference Include="CsvSwan" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CsvSwan --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

CsvSwan is a small .NET Standard CSV parsing library that "just works" for the simplest CSV scenarios. It aims to be high-performance and provide easy-to-use defaults.

using (Csv csv = Csv.Open(@"C:\path\to\file.csv"))
{
    foreach (var row in csv.Rows)
    {
        // Get all values
        IReadOnlyList<string> values = row.GetValues();

        // Map to a numeric type
        int id = row.GetInt(0);
        decimal value = row.GetDecimal(1);
    }
}

You can also map to a list of objects of a given type:

public class MyClass
{
    [CsvColumnOrder(0)]
    public int Id { get; set; }

    [CsvColumnOrder(1)]
    public string Name { get; set; }
}

using (Csv cvs = Csv.Open(@"C:\path\to\file.csv"))
{
    List<MyClass> results = csv.Map<MyClass>().ToList();
}

The default settings are for a file with:

  • A comma separator ,.
  • Newlines between rows, either Unix \n or Windows \r\n.
  • Optional quotes using the double quote &quot; for fields.
  • Quotes inside quoted fields escaped using either RFC-4180 double-double quotes &quot;&quot; (or optionally backslash escaped \&quot;, use CsvOptions.BackslashEscapesQuotes, off by default).

Additionally the user must specify if the file contains a header row prior to parsing using CsvOptions.HasHeaderRow, this is off by default.

The separator and quote character can be set to other values using the CsvOptions parameter to the Csv.Open methods.

Installation

Get it from NuGet or install from the package manager command line:

> Install-Package CsvSwan

CsvSwan is a small .NET Standard CSV parsing library that "just works" for the simplest CSV scenarios. It aims to be high-performance and provide easy-to-use defaults.

using (Csv csv = Csv.Open(@"C:\path\to\file.csv"))
{
    foreach (var row in csv.Rows)
    {
        // Get all values
        IReadOnlyList<string> values = row.GetValues();

        // Map to a numeric type
        int id = row.GetInt(0);
        decimal value = row.GetDecimal(1);
    }
}

You can also map to a list of objects of a given type:

public class MyClass
{
    [CsvColumnOrder(0)]
    public int Id { get; set; }

    [CsvColumnOrder(1)]
    public string Name { get; set; }
}

using (Csv cvs = Csv.Open(@"C:\path\to\file.csv"))
{
    List<MyClass> results = csv.Map<MyClass>().ToList();
}

The default settings are for a file with:

  • A comma separator ,.
  • Newlines between rows, either Unix \n or Windows \r\n.
  • Optional quotes using the double quote &quot; for fields.
  • Quotes inside quoted fields escaped using either RFC-4180 double-double quotes &quot;&quot; (or optionally backslash escaped \&quot;, use CsvOptions.BackslashEscapesQuotes, off by default).

Additionally the user must specify if the file contains a header row prior to parsing using CsvOptions.HasHeaderRow, this is off by default.

The separator and quote character can be set to other values using the CsvOptions parameter to the Csv.Open methods.

Installation

Get it from NuGet or install from the package manager command line:

> Install-Package CsvSwan

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 49 7/4/2020
1.0.0 141 2/16/2020
1.0.0-beta001 111 2/15/2020