Skip to content

Getting started

Mauro Sampietro edited this page Oct 30, 2019 · 10 revisions

UltraMapper supports both manual and by-convention mapping and resolves all type-mappings at runtime.
No registration step is ever required unless you need to override some setting.

By default UltraMapper will try to pair-up members that match their name exactly or that append 'Dto' or 'DataTransferObject' to that target member name. To learn more about conventions read here.

Suppose we are working with the following classes and one instance:

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public float Height { get; set; }
    public float Weight { get; set; }
}

Person personInstance = new Person()
{
    FirstName = "Mauro",
    LastName = "Sampietro",
    Height = 178.0, //cm
    Weight = 67.0, //kg
};

Cloning

To create a copy of the instance:

var mapper = new UltraMapper();
Person clonedPerson = mapper.Map( personInstance );

To copy (overwrite/update) values onto an existing instance:

var mapper = new UltraMapper();

Person clonedPerson = new Person();
mapper.Map( personInstance, clonedPerson );

Mapping to a different type

To get the instance of type 'Person' mapped to an instance of type 'PersonDto' no configuration is needed because of conventions. Notice that 'PersonDto' members' names end with 'Dto' or 'DataTransferObject' and that Heigh and Weight are declared with different types.

private class PersonDto
{
    public string FirstNameDto { get; set; }
    public string LastNameDataTransferObject { get; set; }
    public int HeightDataTransferObject { get; set; }
    public int WeightDto { get; set; }
}

var mapper = new UltraMapper();
PersonDto clonedPerson2 = mapper.Map<PersonDto>( personInstance );
Clone this wiki locally