Status: Not ready for production
Installation
Package Manager Console:
Install-Package RG.CsvSerializer
Usage
using Csv;
// Serialize collection to CSV string
string csv = CsvSerializer.Serialize(items, withHeaders: true);
// Deserialize CSV string to array
Item[] items = CsvSerializer.Deserialize<Item>(csv, hasHeaders: true);
With custom delimiter:
Item[] items = CsvSerializer.Deserialize<Item>(csv, hasHeaders: true, separator: ';');
With custom header name and date format:
class Product {
public string Name { get; set; }
[CsvColumn("Price")]
public decimal PriceBeforeTaxes { get; set; }
[CsvColumn("Added", DateFormat = "dd/MM/yyyy")]
public DateTime Added { get; set; }
}
Supported Property Types
bool
bool?
byte
byte?
sbyte
sbyte?
short
short?
ushort
ushort?
int
int?
uint
uint?
long
long?
ulong
ulong?
float
float?
double
double?
decimal
decimal?
string
DateTime
DateTime?
Uri // serialized as quoted string
Enum // serialized as unquoted string
Enum? // serialized as unquoted string
Not yet supported:
char
char?
DateTimeOffset
DateTimeOffset?
TimeSpan
TimeSpan?
Guid
Guid?
any Object to string (serialize only)
any Object to JSON
any Object to MessagePack Base64
any Object to MessagePack Hex string