Semicolon 0.0.8

dotnet add package Semicolon --version 0.0.8
NuGet\Install-Package Semicolon -Version 0.0.8
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Semicolon" Version="0.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Semicolon --version 0.0.8
#r "nuget: Semicolon, 0.0.8"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.0.8 183 3/13/2024
0.0.7 89 3/13/2024
0.0.6 2,746 1/19/2021
0.0.5 473 12/18/2020
0.0.4 366 12/18/2020
0.0.3 524 11/5/2019
0.0.1 1,401 11/4/2019