Skip to content
Sergey Morenko edited this page Apr 12, 2015 · 1 revision

The sample shows how to map PersonComplex to PersonDtoComplex

public sealed class PersonComplex
{
	public Address Address { get; set; }
	public DateTime CreateTime { get; set; }
	public List<string> Emails { get; set; }
	public string FirstName { get; set; }
	public Guid Id { get; set; }
	public string LastName { get; set; }
	public string Nickname { get; set; }
}

where Address is

public sealed class Address
{
	public string Phone { get; set; }
	public string Street { get; set; }
	public string ZipCode { get; set; }
}

and PersonDtoComplex is

public sealed class PersonDtoComplex
{
	public Address Address { get; set; }
	public DateTime CreateTime { get; set; }
	public List<string> Emails { get; set; }
	public string FirstName { get; set; }
	public Guid Id { get; set; }
	public string LastName { get; set; }
	public string Nickname { get; set; }
}

Bind PersonComplex type to PersonDtoComplex type and we don't want map CreateTime and Nickname properties. So it has been ignored.

TinyMapper.Bind<PersonComplex, PersonDtoComplex>(config =>
{
	config.Ignore(x => x.CreateTime);
	config.Ignore(x => x.Nickname);
});
var person = new PersonComplex
{
	Id = Guid.NewGuid(),
	FirstName = "John",
	LastName = "Doe",
	Address = new Address
	{
		Phone = "Call Me Maybe",
		Street = "Wall Street",
		ZipCode = "101000"
	},
	CreateTime = DateTime.Now,
	Nickname = "Object Mapper",
	Emails = new List<string>
	{
		"help@tinymapper.net",
		"john@tinymapper.net"
	}
};

var personDto = TinyMapper.Map<PersonDtoComplex>(person);
Clone this wiki locally