Semicolon 0.0.8
dotnet add package Semicolon --version 0.0.8
NuGet\Install-Package Semicolon -Version 0.0.8
<PackageReference Include="Semicolon" Version="0.0.8" />
paket add Semicolon --version 0.0.8
#r "nuget: Semicolon, 0.0.8"
// Install Semicolon as a Cake Addin #addin nuget:?package=Semicolon&version=0.0.8 // Install Semicolon as a Cake Tool #tool nuget:?package=Semicolon&version=0.0.8
Semicolon
It's a CSV parser. 🙂
Let's say you're handed some CSV like this:
Player ID;Name;Duration (s)
734;Joe;65
78439;Moe;63
12342;Bo;67
and you want to parse that somehow. This CSV parser can help you. 😁
You start by creating a type with properties for the columns you want to extract (it doesn't have to be all of them):
class CsvRow
{
[CsvColumn("Player ID")]
public string Id { get; set; }
[CsvColumn("Name")]
public string Name { get; set; }
[CsvColumn("Duration (s)", Binder = typeof(ConvertSecondsToTimeSpanBinder))]
public TimeSpan Duration { get; set; }
}
As you can see, the CSV column name is bound to columns from the CSV text by specifying the column name with the [CsvColumn(...)]
attribute.
Another thing to note: Since the duration in the CSV text is specified as an integer (the number of seconds), and we want the value as a TimeSpan
, we make the parser use our own custom binder, ConvertSecondsToTimeSpanBinder
:
class ConvertSecondsToTimeSpanBinder : IBinder
{
public object GetValue(CultureInfo culture, string str) => TimeSpan.FromSeconds(int.Parse(str));
}
Nice. Let's parse the CSV:
var parser = new Parser<CsvRow>();
var rows = parser.ParseCsv(CsvText);
If we now call rows.DumpTable()
(extension method from Testy), we get this:
+-------+------+----------+
| Id | Name | Duration |
+-------+------+----------+
| 734 | Joe | 00:01:05 |
| 78439 | Moe | 00:01:03 |
| 12342 | Bo | 00:01:07 |
+-------+------+----------+
which is what we hoped for. 😎
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.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
- fastmember (>= 1.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.