DwC-A_dotnet.Mapping 0.8.0

dotnet add package DwC-A_dotnet.Mapping --version 0.8.0                
NuGet\Install-Package DwC-A_dotnet.Mapping -Version 0.8.0                
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="DwC-A_dotnet.Mapping" Version="0.8.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DwC-A_dotnet.Mapping --version 0.8.0                
#r "nuget: DwC-A_dotnet.Mapping, 0.8.0"                
#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 DwC-A_dotnet.Mapping as a Cake Addin
#addin nuget:?package=DwC-A_dotnet.Mapping&version=0.8.0

// Install DwC-A_dotnet.Mapping as a Cake Tool
#tool nuget:?package=DwC-A_dotnet.Mapping&version=0.8.0                

DwC-A_dotnet.Mapping Documentation

DwC-A_dotnet.Mapping is an extension library of DwC-A_dotnet for mapping Darwin Core Archive data to strongly typed classes.

Install

To add DwC-A_dotnet.Mapping to your project run the following command in the Visual Studio Package Manager Console

PM> Install-Package DwC-A_dotnet.Mapping

Usage

There are two methods of mapping an IRow to a strongly typed class

  1. Using a lambda or delegate.
  2. Using the Term attribute.

Lambda Mapping

This technique gives the most control over mapping but requires the mapper to be configured for your particular class as follows.

Assuming the following simple occurrence class type

public class Occurrence
{
    public string Id {get; set;}
    public string ScientificName {get; set;}
    public double Longitude {get; set;}
    public double Latitude {get; set;}
}

A mapper should be set up as follows

IMapper<Occurrence> mapper = MapperFactory.CreateMapper<Occurrence>((o, row) =>
{
    o.Id = row["id"];
    o.DecimalLatitude = row.Convert<double>(Terms.decimalLatitude);
    o.DecimalLongitude = row.Convert<double>(Terms.decimalLongitude);
    o.ScientificName = row[Terms.scientificName];
});

The mapper can then be used to map rows from an occurrence file as follows.

using DwC_A;
using DwC_A.Mapping;
using DwC_A.Terms;

using(ArchiveReader archive = new ArchiveReader("archivePath"))
{
    foreach(var row in archive.CoreFile.DataRows)
    {
        var occurrence = row.Map<Occurrence>(mapper);
        ...
    }
}

Attribute Mapping

This method uses classes that have been annotated with the Term attribute to associate fields with properties.

First create a class and add Term attributes to each property that you wish to be mapped.

using DwC_A.Attributes;

public class Occurrence
{
    [Term("id")]
    public string Id {get; set;}
    [Term("http://rs.tdwg.org/dwc/terms/scientificName")]
    public string ScientificName {get; set;}
    [Term("http://rs.tdwg.org/dwc/terms/decimalLongitude")]
    public double Longitude {get; set;}
    [Term("http://rs.tdwg.org/dwc/terms/decimalLatitude")]
    public double Latitude {get; set;}
}

The DwC-A_dotnet library then uses a Source Generator to add a map method to the annotated class which can be used to define a mapper as follows.

IMapper<Occurrence> mapper = MapperFactory.CreateMapper<Occurrence>((o, row) => o.MapRow(row));

Mapping Extensions

Once an IMapper instance has been created it can be used to map an individual row or an enumeration in one of the following ways.

Single Row
Occurrence occurrence = row.Map<Occurrence>(mapper);

OR

Occurrence occurrence = mapper.MapRow(row);

Also, if you are using Attribute Mapping the source generator will add a MapRow extension method to your class so you can map it as follows.

Occurrence occurrence = new Occurrence();
occurrence.MapRow(row);
FileReader DataRows Enumeration
using(ArchiveReader archive = new ArchiveReader("archivePath"))
{
    foreach(var occurrence in archive.CoreFile.Map<Occurrence>(mapper))
    {
        ...
    }
}
Enumeration of IRow

Use this technique to filter rows before mapping for improved performance

using(ArchiveReader archive = new ArchiveReader("archivePath"))
{
    foreach(var occurrence in archive.CoreFile.Take(10).Map<Occurrence>(mapper))
    {
        ...
    }
}

Class Generation

To ease the creation of class definitions for large files the dwca-codegen CLI tool was created and can also be downloaded from NuGet. See the dwca-codegen documentation for more information.

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 (1)

Showing the top 1 NuGet packages that depend on DwC-A_dotnet.Mapping:

Package Downloads
DwC-A_dotnet.Interactive

.NET Interactive Extensions for Darwin Core Archive file reader

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.8.0 211 12/12/2023
0.7.0 372 11/14/2022
0.6.3 1,909 11/26/2021
0.6.2 1,606 11/26/2021
0.6.1 288 11/22/2021
0.6.0 358 11/14/2021