Helpwiz.FastCsvReader
1.0.1
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
<PackageReference Include="Helpwiz.FastCsvReader" Version="1.0.1" />
paket add Helpwiz.FastCsvReader --version 1.0.1
#r "nuget: Helpwiz.FastCsvReader, 1.0.1"
// 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 | Versions 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. |
-
.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.
Added multi-attribute reading, to allow multiple field names to map to a single property.