Skip to content

Getting Started

TacoMapper can be installed via NuGet Package Manager or by adding a project reference.

Terminal window
dotnet add package TacoMapper

If you’re building from source or using the library locally:

Terminal window
dotnet add reference path/to/lib/TacoMapper.csproj

The simplest way to use TacoMapper is with auto-mapping for objects with matching property names and types:

using TacoMapper.Core;
// Assuming Person and PersonDto have matching properties
var person = new Person
{
Id = 1,
FirstName = "John",
LastName = "Doe"
};
var personDto = ObjectMapper.Map<Person, PersonDto>(person);

For more control over the mapping process, use the fluent API:

var mapper = ObjectMapper.Create<Person, PersonDto>()
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.Email, src => src.Email)
.Combine(dest => dest.FullName, src => $"{src.FirstName} {src.LastName}");
var result = mapper.MapFrom(person);

TacoMapper supports mapping collections efficiently:

var people = new List<Person> { /* your data */ };
// Using a configured mapper
var mapper = ObjectMapper.Create<Person, PersonDto>()
.Map(dest => dest.Id, src => src.Id)
.Combine(dest => dest.FullName, src => $"{src.FirstName} {src.LastName}");
var results = mapper.MapFrom(people);
// Or simple auto-mapping for collections
var simpleResults = ObjectMapper.Map<Person, PersonDto>(people);
  • .NET 8.0 or later
  • C# 12.0 language features