automapper 1.1.0

D automapper

To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:


AutoMapper is an object-object mapper for D like C# AutoMapper.

It use compile-time generated mapper to try to avoid any overhead.

You can run the benchmark located in tests/benchmark:

$ cd tests/benchmark
$ dub test

Build documentation

This project is well documented:

$ dub build --build=ddox

Full exemple

import std.stdio;
import automapper;

class Order
    Customer customer;
    Product product;

class Product
    float price;
    string name;

class Customer
    string name;
    string city;
    string email;

class OrderDTO
    string customerName;
    string customerCity;
    string customerEmail;
    float productPrice;
    string productName;

auto makeOrder()
    auto order = new Order();
    order.customer = new Customer(); = "boolangery"; = "Annecy"; = "[email protected]";
    order.product = new Product();
    order.product.price = 42; = "universe";
    return order;

void main()
    // create a compile-time generated mapper to map from Order to OrderDTO,
    // and from OrderDTO to Order.
    auto mapper = MapperConfiguration!(
        CreateMap!(Order, OrderDTO)

    auto initial = makeOrder();
    auto dto     =!OrderDTO(initial); // map Order to OrderDTO
    auto order   =!Order(dto); // map back OrderDTO to Order

    assert(  ==;
    assert(  ==;
    assert( ==;
    assert(order.product.price  == initial.product.price);
    assert(   ==;

    // more suitable runtime mapper
    RuntimeAutoMapper m = mapper.createRuntimeContext();

Run Time

To be as fast as possible, AutoMapper do by deafult all its magic at compile-time (See example bellow). Mapping check are static asserted.

It implies that AutoMapper type is specialized using templates:

alias AM = AutoMapper!(MapperConfiguration!(CreateMap!(Order, OrderDTO, ReverseMapConfig)));

AM mapper = MapperConfiguration!(
        CreateMap!(Order, OrderDTO)

It may be difficult to pass this complex object along your framework. Its why you can use a slower version, that check things at runtime.

The example above became:

RuntimeAutoMapper mapper = MapperConfiguration!(
        CreateMap!(Order, OrderDTO)

Custom member mapping

import automapper;
import std.datetime;

class A {
    long timestamp;

class B {
    SysTime timestamp;

auto am = MapperConfiguration!(
    CreateMap!(long, SysTime)
        .ConvertUsing!((long ts) => SysTime(ts)),
    CreateMap!(A, B))
  • Eliott Dumeix
1.1.0 2019-Jan-24
1.0.0 2019-Jan-15
~master 2019-Jan-24
Show all 3 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 12 downloads total

Short URL: