List and Arrays

Powerful convention-based, customizable and fastest tool for object-object mapping.It is useful for Entity to DTO, DTO to Entity mapping strategies.

The latest builds can be found at NuGet

Sample

Test Classes:

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal? Credit { get; set; }
    public DateTime CreateDate { get; set; }
}

public class CustomerDTO
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal? Credit { get; set; }
}


Test Data

public List<Customer> GetCustomers()
{
    Customer customer = new Customer()
    {
       Id = 1,
       Name = "Timucin Kivanc",
       Credit = 234.7m,
       CreateDate = DateTime.Now
    };

    var customerList = new List<Customer>(){ customer };

    return customerList;
}


Map:

var customers = GetCustomers();

var customerDtoList = TypeAdapter.Adapt<List<Customer>, List<CustomerDTO>>(customers);

// result:
// customerDtoList.Count == 1
// customerDtoList[0].Id == 1
// customerDtoList[0].Name == "Timucin Kivanc"
// customerDtoList[0].Credit == 234.7m

// or

var customerDtoArray = TypeAdapter.Adapt<List<Customer>, CustomerDTO[]>(customers);

// result:
// customerDtoArray.Length == 1
// customerDtoArray[0].Id == 1
// customerDtoArray[0].Name == "Timucin Kivanc"
// customerDtoArray[0].Credit == 234.7m


Last edited Mar 28, 2014 at 11:14 AM by timucinkivanc, version 2