Complex mapping - TinyMapper/TinyMapper GitHub Wiki

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>
	{
		"[email protected]",
		"[email protected]"
	}
};

var personDto = TinyMapper.Map<PersonDtoComplex>(person);
⚠️ **GitHub.com Fallback** ⚠️