Complex Model

Test Classes

public class Address
{
    public int Id { get; set; }
    public string Street { get; set; }
    public string City { get; set; }
    public string Country { get; set; }
}

public class AddressDTO
{
    public int Id { get; set; }
    public string City { get; set; }
    public string Country { get; set; }
}

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal? Credit { get; set; }
    public Address HomeAddress { get; set; }
 }

 public class CustomerDTO
 {
    public int Id { get; set; }
    public string Name { get; set; }
    public AddressDTO HomeAddress { get; set; }
 }


Test Data

public Customer GetCustomer()
{
    Customer customer = new Customer()
    {
        Id = 1,
        Name = "Timucin Kivanc",
        Credit = 234.7m,
        HomeAddress = new Address() { 
            City = "Istanbul", 
            Country = "Turkey", 
            Id = 2, 
            Street = "Istiklal cad." 
        }
    };

    return customer;
}


Map

var customerDto = TypeAdapter.Adapt<Customer, CustomerDTO>(GetCustomer());

//result : 
// customerDto.Id == 1
// customerDto.Name == "Timucin Kivanc"
// customerDto.HomeAddress.City == "Istanbul"
...
//All properties mapped

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