Nukepayload2.Csv 1.1.0

Nukepayload2.Csv is a cross-platform Csv String <==> .NET Object converter.
Commonly Used members:
Nukepayload2.Csv.CsvConvert.SerializeObject
Nukepayload2.Csv.CsvConvert.DeserializeObject
Supported types in csv columns:
System.String
System.DateTime
System.Int32
System.Int64
System.Single
System.Double

There is a newer version of this package available.
See the version list below for details.
Install-Package Nukepayload2.Csv -Version 1.1.0
dotnet add package Nukepayload2.Csv --version 1.1.0
<PackageReference Include="Nukepayload2.Csv" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nukepayload2.Csv --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Sample Code

Convert Csv string to .NET Object

Goal: convert the following csv string to .NET Object.

Id,Rate,Name,Date,IsUsed
-233,12345.12,test string,2018-05-09,True
0,-12345.12,,2018-09-09,False
1. Create a model class

VB

Public Class MyCsvModel
    Public Property Id As Integer
    Public Property Rate As Double
    Public Property Name As String
    Public Property [Date] As Date
    Public Property IsUsed As Boolean
End Class

C#

public class MyCsvModel
{
    public int Id { get; set; }
    public double Rate { get; set; }
    public string Name { get; set; }
    public DateTime Date { get; set; }
    public bool IsUsed { get; set; }
}
2. Convert csv to IReadOnlyList of MyCsvModel

Assume that csv is a System.String that contains csv.

VB

Dim converted = CsvConvert.DeserializeObject(Of MyCsvModel)(csv)

C#

var converted = CsvConvert.DeserializeObject<MyCsvModel>(csv);

Convert .NET Object back to Csv string

VB

csv = CsvConvert.SerializeObject(converted)

C#

csv = CsvConvert.SerializeObject(converted);

Trouble shooting

If these sample codes throw FormatException when deserializing, please set the current culture of the current thread to "zh-CN".
Because I'm using Chinese date time format when writing this sample.

Sample Code

Convert Csv string to .NET Object

Goal: convert the following csv string to .NET Object.

Id,Rate,Name,Date,IsUsed
-233,12345.12,test string,2018-05-09,True
0,-12345.12,,2018-09-09,False
1. Create a model class

VB

Public Class MyCsvModel
    Public Property Id As Integer
    Public Property Rate As Double
    Public Property Name As String
    Public Property [Date] As Date
    Public Property IsUsed As Boolean
End Class

C#

public class MyCsvModel
{
    public int Id { get; set; }
    public double Rate { get; set; }
    public string Name { get; set; }
    public DateTime Date { get; set; }
    public bool IsUsed { get; set; }
}
2. Convert csv to IReadOnlyList of MyCsvModel

Assume that csv is a System.String that contains csv.

VB

Dim converted = CsvConvert.DeserializeObject(Of MyCsvModel)(csv)

C#

var converted = CsvConvert.DeserializeObject<MyCsvModel>(csv);

Convert .NET Object back to Csv string

VB

csv = CsvConvert.SerializeObject(converted)

C#

csv = CsvConvert.SerializeObject(converted);

Trouble shooting

If these sample codes throw FormatException when deserializing, please set the current culture of the current thread to "zh-CN".
Because I'm using Chinese date time format when writing this sample.

Release Notes

Improved performance for huge csv strings.

  • .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 History

Version Downloads Last updated
1.4.0 942 6/10/2019
1.3.3 568 1/6/2019
1.3.2 437 8/17/2018
1.3.1 294 8/14/2018
1.3.0 306 8/2/2018
1.2.0 405 5/22/2018
1.1.0 367 5/17/2018
1.0.3 413 5/13/2018
1.0.2 385 5/13/2018
1.0.1 394 5/12/2018
1.0.0 324 5/11/2018
Show less