Skip to content
Sanam edited this page Oct 7, 2026 · 2 revisions

Docs for DotNetMapper, a zero-config object mapper for .NET with one method.

Every example on these pages was run against the published package, and the outputs shown are what it printed. Current version: 2.0.0.

dotnet add package DotNetMapper

The one method

public static TOutput Map<TInput, TOutput>(TInput inputObject) where TOutput : new()

It creates a new TOutput() and copies every public property that has the same name and the same type in both. Nothing else: no configuration, no conversion, no deep copy.

using DotNetMapper;

public class UserEntity
{
    public int Id { get; set; }
    public string Name { get; set; } = "";
    public string PasswordHash { get; set; } = "";
    public List<string> Tags { get; set; } = [];
}

public class UserDto
{
    public int Id { get; set; }
    public string Name { get; set; } = "";
    public List<string> Tags { get; set; } = [];
}

var entity = new UserEntity { Id = 1, Name = "Ada", PasswordHash = "x9f", Tags = ["admin"] };
UserDto dto = Mapper.Map<UserEntity, UserDto>(entity);

Console.WriteLine($"{dto.Id} {dto.Name}");                // 1 Ada
Console.WriteLine(ReferenceEquals(dto.Tags, entity.Tags)); // True

PasswordHash has no match on UserDto, so it is not copied. Tags is copied by reference: both objects now share one list.

Pages

You want to know Read
Exactly which properties are copied, and why one was not Mapping rules
Whether your call runs generated code, and what happens when it does not Generated code
What changed from 1.x Migrating from 1x

Collections

There is no list overload. Use what .NET already has:

List<UserDto> dtos = users.ConvertAll(u => Mapper.Map<UserEntity, UserDto>(u));
UserDto[] array = users.Select(u => Mapper.Map<UserEntity, UserDto>(u)).ToArray();

Both calls run generated code, because the lambda names concrete types.

When to use something else

If you need renaming, type conversion, flattening, or configuration per mapping, use Mapperly. DotNetMapper is deliberately the case where names and types already line up.

Clone this wiki locally