Helpwiz.FastCsvReader 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Helpwiz.FastCsvReader --version 1.0.1
NuGet\Install-Package Helpwiz.FastCsvReader -Version 1.0.1
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="Helpwiz.FastCsvReader" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Helpwiz.FastCsvReader --version 1.0.1
#r "nuget: Helpwiz.FastCsvReader, 1.0.1"
#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.
// Install Helpwiz.FastCsvReader as a Cake Addin
#addin nuget:?package=Helpwiz.FastCsvReader&version=1.0.1

// Install Helpwiz.FastCsvReader as a Cake Tool
#tool nuget:?package=Helpwiz.FastCsvReader&version=1.0.1

Helpwiz.FastCsvReader

A fast compiled expression based csv reader.

Capabilities

Allows custom delimiter characters. Allows quoted values with commas inside e.g. "My value, my second value and my third value"

Limitations

Does not allow multi-line values Does not allow values containing quotes (i.e. no escaped quotes). Requires a header row for the csv file.

Performance

Because the property access expressions are compiled, the library will load csv files at the maximum speed possible.

Getting started

Basic Usage

If you want the csv data to populate a class, make settable properties of all the header fields in the class, and the reader will read into that class

private string[] testData = new []
{ 
  "A, B, C, D", 
  "1,Two,3.0,"
};

private class TargetType 
{
  public int A { get; set; }
  
  public string B { get; set; }
  
  public double C { get; set; }
  
  public int? D { get; set; }
}

//...

public IEnumerable<TargetType> ReadElements() => FastCsvReader.ReadAs<TargetType>(testData);

Named properties

If you want the properties of the target type to differ in name from the header fields, you can use a [CsvProperty] attribute. Note header names are trimmed when matching to properties.

private string[] testData = new[]
{
  "A property, B property, C property, D property",
  "1,Two,3.0,"
};

private class TargetType 
{
  [CsvProperty("A property")]
  public int A { get; set; }
  
  [CsvProperty("B property")]
  public string B { get; set; }
  
  [CsvProperty("C property")]
  public double C { get; set; }
  
  [CsvProperty("D property")]
  public int? D { get; set; }
}

Data conversion and Custom Delimiters

Sensible defaults for string, int, double, DateTime, int?, double? and DateTime? are provided by default. You can override the default behaviour of this and extend to other datatypes as follows:

  var converter = new DefaultConverterSpec();
  converter.SetConverter<int?>(s =>
  {
    if (string.IsNullOrWhiteSpace(s)) return null;
    if (!int.TryParse(s, out int value)) return null;
    return value;
  });
  
  //Read the file with ¬ as the delimiter character and with custom handling for nullable integers.
  var result = FastCsvReader.ReadAs<DefaultData2>(testData3, '¬', converter).ToArray();

Helpwiz

Helpwiz is an online marketplace for independent domestic cleaners. We allow clients to find a cleaner and book a clean in a simple, one-pass process. We have cleaners in many locations throughout the UK.

We provide this code for free, without any license contraints, but we do hope that, if you make use of the code, you will link back to us or otherwise give us a shout out.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • 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
1.0.6 398 2/7/2021
1.0.5 426 11/26/2020
1.0.4 403 11/19/2020
1.0.3 413 11/18/2020
1.0.2 392 11/18/2020
1.0.1 368 11/17/2020
1.0.0 412 11/16/2020

Added multi-attribute reading, to allow multiple field names to map to a single property.