Adr.SimpleMapper 2.2.0

Config-less mapping in C#. As simple as it gets.

Install-Package Adr.SimpleMapper -Version 2.2.0
dotnet add package Adr.SimpleMapper --version 2.2.0
<PackageReference Include="Adr.SimpleMapper" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Adr.SimpleMapper --version 2.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Build Status

Version 2.2.0 is here

Quick Start

Default Mapping

public class Order
{
  public string Id {get; set;}
  public DateTime PlacementDate {get; set;}
  public bool IsGift {get; set;}
}

public class PendingOrder : BaseMappable<Order, PendingOrder>
{
  public string Id {get; set;}
  public string Status {get; set;}
  public bool IsGift {get; set;}
  public DateTime PlacementDate {get; set;}
}

public void PerformTheMapping()
{
  var order = _orderRepo.Get("A124B2");
  var mapSlave = new PendingOrder();
  //`mappedEntity` is of type `PendingOrder`
  var mappedEntity = mapSlave.Map(order);
}

From the above example, we can see that the mapping attributes go on the result class and not the source class. We can also see that PendingOrder contains property: Status which Order does not. By default, SimpleMapper only maps common properties. This can be overriden with the RequireAllPropertiesAttribute. See below for an example

Using RequireAllPropertiesAttribute

public class Cat 
{
  public string Breed {get; set;}
  public double Weight {get; set;}
}

[RequireAllProperties]
public class WildCat : BaseMappable<Cat, WildCat>
{
  public string Breed {get; set;}
  public string Weight {get; set;}
  public string Region {get; set;}
}

When performing a call to Map on WildCat a MissingMemberException will be thrown.

Build Status

Version 2.2.0 is here

Quick Start

Default Mapping

public class Order
{
  public string Id {get; set;}
  public DateTime PlacementDate {get; set;}
  public bool IsGift {get; set;}
}

public class PendingOrder : BaseMappable<Order, PendingOrder>
{
  public string Id {get; set;}
  public string Status {get; set;}
  public bool IsGift {get; set;}
  public DateTime PlacementDate {get; set;}
}

public void PerformTheMapping()
{
  var order = _orderRepo.Get("A124B2");
  var mapSlave = new PendingOrder();
  //`mappedEntity` is of type `PendingOrder`
  var mappedEntity = mapSlave.Map(order);
}

From the above example, we can see that the mapping attributes go on the result class and not the source class. We can also see that PendingOrder contains property: Status which Order does not. By default, SimpleMapper only maps common properties. This can be overriden with the RequireAllPropertiesAttribute. See below for an example

Using RequireAllPropertiesAttribute

public class Cat 
{
  public string Breed {get; set;}
  public double Weight {get; set;}
}

[RequireAllProperties]
public class WildCat : BaseMappable<Cat, WildCat>
{
  public string Breed {get; set;}
  public string Weight {get; set;}
  public string Region {get; set;}
}

When performing a call to Map on WildCat a MissingMemberException will be thrown.

Release Notes

- Moved mapping attributes to result class as opposed to the old way of being on the source class
- Added support for nullable property types

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.2.0 299 6/25/2018
1.1.0 5,204 3/26/2018
1.0.0 358 3/25/2018