Get Started with NetCore.Mapper
See how easy it is to install, configure, and run your first mapping.
Installation
To install the library, run the following command in your .NET project terminal:
dotnet add package Flavio.Santos.NetCore.ObjectMapping
Basic example
Here is a minimal example to understand how the automatic mapping works:
public class PersonDto
{
public string Name { get; set; }
public string Gender { get; set; } // string representing the enum
}
public enum Gender
{
Male,
Female
}
public class Person
{
public string Name { get; set; }
public Gender Gender { get; set; }
}
Now, to map PersonDto to Person, just write:
var dto = new PersonDto { Name = "Alice", Gender = "Female" };
var person = dto.MapTo<Person>();
The
Genderfield, even as a string, will be automatically converted to theGenderenum.
Fluent chaining with .Apply()
In addition to mapping, you can fluently apply changes using .Apply():
var person = dto
.MapTo<Person>()
.Apply(p => p.Id = Guid.NewGuid());
No additional configuration
No need to register profiles, define rules, or create configuration instances.
Mapping works automatically based on property name and type compatibility.