GSoulavy.Csv.Net
2.3.9
dotnet add package GSoulavy.Csv.Net --version 2.3.9
NuGet\Install-Package GSoulavy.Csv.Net -Version 2.3.9
<PackageReference Include="GSoulavy.Csv.Net" Version="2.3.9" />
paket add GSoulavy.Csv.Net --version 2.3.9
#r "nuget: GSoulavy.Csv.Net, 2.3.9"
// Install GSoulavy.Csv.Net as a Cake Addin
#addin nuget:?package=GSoulavy.Csv.Net&version=2.3.9
// Install GSoulavy.Csv.Net as a Cake Tool
#tool nuget:?package=GSoulavy.Csv.Net&version=2.3.9
GSoulavy.Csv.Net
Simple csv .Net Standard 2.0 parser library
Usage
Attributes
ClassAttribute:
CsvFileAttribute
fileAttribute has three parameters:
- HasHeaders (
bool
): declares if the input file has header or not, - Separator (
char
): define the column separator, - StringQuotes (
char
): declares the quotation → default is'\0'
(it will trim the given value when it's declared e.g"
or'
)
PropertyAttribute
CsvColumnAttribute
has two properties:
- Name (
string
): mapping name of the csv header, - Position (
int
): the position of the column
Source file:
name, age
Gabs, 35
Joe, 40
Mapping (v1.1):
[CsvFile(HasHeaders = true, Separator = ',')]
public class Person
{
[CsvColumn("name")]
public string Name { get; set; }
[CsvColumn("age")]
public int Age { get; set; }
[CsvIgnore]
public string Title { get; set; }
[CsvColumn("dob", Format = "yyyy-M-d")]
public DateTime DateOfBirth { get; set; }
}
Mapping (v2.0)
You need to implement the ICustomConversion interface in order to achieve custom conversion and pass as a type into your CsvColumnAttribute
The ICustomConversion
inteface:
public interface ICustomConversion
{
object Parse(string value);
string Compose(object value);
}
The ICustomConversion
inteface:
An example implementaion for example by you as CustomDateTimeConversion
:
public class CustomDateTimeConversion : ICustomConversion
{
private const string Format = "d.M.yyyy";
public object Parse(string value)
{
return DateTime.TryParseExact(value, Format, CultureInfo.InvariantCulture,
DateTimeStyles.None,
out var parsedDate) ? parsedDate : DateTime.MinValue;
}
public string Compose(object value)
{
return ((DateTime) value).ToString(Format);
}
}
Your model declaration:
[CsvFile(HasHeaders = true, Separator = ';')]
public class FileWithHeaderDateAndSemi
{
[CsvColumn("name")]
public string Name { get; set; }
[CsvColumn("age")]
public int Age { get; set; }
[CsvIgnore]
public string Title { get; set; }
[CsvColumn("dob", typeof(CustomDateTimeConversion))]
public DateTime DateOfBirth { get; set; }
}
Desiralizing in action:
var list = CsvConvert.Deserialize<Person>(text).ToList();
Serializing in action:
var csv = CsvConvert.Serialize(list);
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.
Version | Downloads | Last updated |
---|---|---|
2.3.9 | 78 | 2/15/2024 |
2.3.8 | 149 | 6/29/2023 |
2.3.7 | 120 | 5/24/2023 |
2.3.5 | 292 | 12/9/2021 |
2.3.4 | 397 | 3/20/2021 |
2.3.3 | 1,571 | 9/11/2019 |
2.3.2 | 482 | 9/10/2019 |
2.2.2 | 1,536 | 7/23/2019 |
2.2.1 | 482 | 7/23/2019 |
2.2.0 | 480 | 7/22/2019 |
2.1.0 | 532 | 3/10/2019 |
2.0.0 | 621 | 2/2/2019 |
1.1.0 | 617 | 1/31/2019 |
1.0.0 | 649 | 11/29/2018 |