Quick.Mapper 8.0.1

dotnet add package Quick.Mapper --version 8.0.1
                    
NuGet\Install-Package Quick.Mapper -Version 8.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Quick.Mapper" Version="8.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Quick.Mapper" Version="8.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Quick.Mapper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Quick.Mapper --version 8.0.1
                    
#r "nuget: Quick.Mapper, 8.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Quick.Mapper@8.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Quick.Mapper&version=8.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Quick.Mapper&version=8.0.1
                    
Install as a Cake Tool

Quick.Mapper 🚀

NuGet NuGet Downloads License: MIT

Un mapper rápido, eficiente y fácil de usar para .NET, con API idéntica a AutoMapper pero optimizado para rendimiento.

✨ Características

  • 🎯 API Idéntica a AutoMapper: Sintaxis 100% compatible con AutoMapper
  • Alto Rendimiento: Optimizado para mapeos rápidos
  • 🔧 Configuración Flexible: Mapeos automáticos y personalizados
  • 📦 Dependency Injection: Integración nativa con Microsoft.Extensions.DependencyInjection
  • 🎨 Perfiles: Organiza tus mapeos en perfiles reutilizables
  • 🔄 ReverseMap: Soporte completo para mapeo inverso automático
  • 🎭 Hooks: BeforeMap y AfterMap para lógica personalizada
  • 🛡️ Type Safety: Fuertemente tipado con soporte completo para genéricos
  • 📝 Constructor en Perfiles: Define mapeos directamente en el constructor del Profile

📦 Instalación

Via NuGet Package Manager

Install-Package Quick.Mapper

Via .NET CLI

dotnet add package Quick.Mapper

Via PackageReference

<PackageReference Include="Quick.Mapper" Version="8.0.1" />

🚀 Inicio Rápido

Configuración Básica

using Quick.Mapper;
using Quick.Mapper.Configuration;

// Crear configuración
var config = new MapperConfiguration(cfg =>
{
    cfg.CreateMap<User, UserDto>();
    cfg.CreateMap<Order, OrderDto>();
});

// Crear mapper
var mapper = config.CreateMapper();

// Mapear objetos
var userDto = mapper.Map<UserDto>(user);

Con Dependency Injection

// En Program.cs o Startup.cs
using Quick.Mapper.Extensions;

builder.Services.AddQuickMapper(cfg =>
{
    cfg.CreateMap<User, UserDto>();
    cfg.CreateMap<Order, OrderDto>();
});

// Usar en tus servicios
public class UserService
{
    private readonly IMapper _mapper;

    public UserService(IMapper mapper)
    {
        _mapper = mapper;
    }

    public UserDto GetUser(int id)
    {
        var user = _repository.GetById(id);
        return _mapper.Map<UserDto>(user);
    }
}

📚 Ejemplos de Uso

Mapeo Simple

public class User
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
}

public class UserDto
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
}

// Configuración
var config = new MapperConfiguration(cfg =>
{
    cfg.CreateMap<User, UserDto>();
});

var mapper = config.CreateMapper();
var userDto = mapper.Map<UserDto>(user);

Mapeo Personalizado con ForMember

var config = new MapperConfiguration(cfg =>
{
    cfg.CreateMap<User, UserDto>()
        .ForMember(dest => dest.FullName, 
            opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"))
        .ForMember(dest => dest.Age, 
            opt => opt.MapFrom(src => DateTime.Now.Year - src.BirthYear))
        .ForMember(dest => dest.IsActive, 
            opt => opt.Ignore());
});

Mapeo Condicional

cfg.CreateMap<User, UserDto>()
    .ForMember(dest => dest.Email, opt => 
    {
        opt.Condition(src => src.IsEmailPublic);
        opt.MapFrom(src => src.Email);
    });

Mapeo con Valor Constante

cfg.CreateMap<User, UserDto>()
    .ForMember(dest => dest.Status, opt => opt.UseValue("Active"))
    .ForMember(dest => dest.CreatedBy, opt => opt.UseValue("System"));

Hooks: BeforeMap y AfterMap

cfg.CreateMap<User, UserDto>()
    .BeforeMap((src, dest) => 
    {
        Console.WriteLine($"Mapeando usuario {src.Id}");
    })
    .AfterMap((src, dest) => 
    {
        dest.MappedAt = DateTime.UtcNow;
        dest.Version = "1.0";
    });

Constructor Personalizado

cfg.CreateMap<User, UserDto>()
    .ConstructUsing(src => new UserDto(src.Id, src.Email));

Mapeo Inverso (ReverseMap)

cfg.CreateMap<User, UserDto>()
    .ForMember(dest => dest.FullName, 
        opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"))
    .ReverseMap(); // ✅ Crea automáticamente UserDto -> User

Mapeo a Objeto Existente

var existingDto = new UserDto();
mapper.Map(user, existingDto); // Actualiza el objeto existente

🎨 Usando Perfiles

Los perfiles permiten organizar configuraciones de mapeo relacionadas. La sintaxis es idéntica a AutoMapper:

using Quick.Mapper.Profiles;

public class UserProfile : Profile
{
    public UserProfile()  // ✅ Define mapeos en el constructor
    {
        CreateMap<User, UserDto>()
            .ForMember(dest => dest.FullName, 
                opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"))
            .ReverseMap();
        
        CreateMap<Address, AddressDto>()
            .ReverseMap();
    }
}

public class OrderProfile : Profile
{
    public OrderProfile()
    {
        CreateMap<Order, OrderDto>();
        CreateMap<OrderItem, OrderItemDto>();
    }
}

Registrar Perfiles

// Opción 1: Manualmente
var config = new MapperConfiguration(cfg =>
{
    cfg.AddProfile<UserProfile>();
    cfg.AddProfile<OrderProfile>();
});

// Opción 2: Con Dependency Injection
builder.Services.AddQuickMapper(cfg =>
{
    cfg.AddProfile<UserProfile>();
    cfg.AddProfile<OrderProfile>();
});

Auto-descubrimiento de Perfiles

Quick.Mapper puede escanear automáticamente todos los perfiles en un ensamblado:

// Escanea todos los perfiles en el ensamblado actual
builder.Services.AddQuickMapper(Assembly.GetExecutingAssembly());

// Escanea usando un tipo marcador
builder.Services.AddQuickMapper<Program>();

// Escanea múltiples ensamblados
builder.Services.AddQuickMapper(
    Assembly.GetExecutingAssembly(),
    typeof(SomeOtherType).Assembly
);

Registrar perfiles por tipo

builder.Services.AddQuickMapper(
    typeof(UserProfile),
    typeof(OrderProfile),
    typeof(ProductProfile)
);

🔧 Características Avanzadas

Validación de Configuración

var config = new MapperConfiguration(cfg =>
{
    cfg.CreateMap<User, UserDto>();
});

// Valida que todos los mapeos son correctos
config.AssertConfigurationIsValid();

Obtener Mapeos Registrados

var typeMaps = config.GetAllTypeMaps();
foreach (var typeMap in typeMaps)
{
    Console.WriteLine($"{typeMap.SourceType.Name} -> {typeMap.DestinationType.Name}");
}

Mapeo No Genérico

Útil cuando trabajas con reflexión o tipos dinámicos:

Type sourceType = typeof(User);
Type destType = typeof(UserDto);

object result = mapper.Map(user, sourceType, destType);

Mapeo a Objeto Existente (No Genérico)

mapper.Map(user, existingDto, typeof(User), typeof(UserDto));

📖 Ejemplos Completos

Ejemplo: Sistema de Usuario

// Modelos
public class User
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public DateTime BirthDate { get; set; }
    public bool IsEmailPublic { get; set; }
}

public class UserDto
{
    public int Id { get; set; }
    public string FullName { get; set; }
    public string Email { get; set; }
    public int Age { get; set; }
}

// Profile
public class UserProfile : Profile
{
    public UserProfile()
    {
        CreateMap<User, UserDto>()
            .ForMember(dest => dest.FullName, 
                opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"))
            .ForMember(dest => dest.Age,
                opt => opt.MapFrom(src => DateTime.Now.Year - src.BirthDate.Year))
            .ForMember(dest => dest.Email, opt =>
            {
                opt.Condition(src => src.IsEmailPublic);
                opt.MapFrom(src => src.Email);
            });
    }
}

// Configuración en Startup
builder.Services.AddQuickMapper(cfg =>
{
    cfg.AddProfile<UserProfile>();
});

// Uso en Controller
[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
    private readonly IMapper _mapper;
    private readonly IUserRepository _repository;

    public UsersController(IMapper mapper, IUserRepository repository)
    {
        _mapper = mapper;
        _repository = repository;
    }

    [HttpGet("{id}")]
    public ActionResult<UserDto> GetUser(int id)
    {
        var user = _repository.GetById(id);
        if (user == null)
            return NotFound();

        var userDto = _mapper.Map<UserDto>(user);
        return Ok(userDto);
    }

    [HttpPost]
    public ActionResult<UserDto> CreateUser(CreateUserDto dto)
    {
        var user = _mapper.Map<User>(dto);
        _repository.Add(user);
        
        var userDto = _mapper.Map<UserDto>(user);
        return CreatedAtAction(nameof(GetUser), new { id = user.Id }, userDto);
    }
}

Ejemplo: Mapeo Bidireccional con ReverseMap

public class ProductProfile : Profile
{
    public ProductProfile()
    {
        CreateMap<Product, ProductDto>()
            .ForMember(dest => dest.CategoryName,
                opt => opt.MapFrom(src => src.Category.Name))
            .ForMember(dest => dest.TotalStock,
                opt => opt.MapFrom(src => src.Stock + src.ReservedStock))
            .ReverseMap()  // Crea automáticamente ProductDto -> Product
            .ForMember(dest => dest.Category, opt => opt.Ignore())
            .ForMember(dest => dest.ReservedStock, opt => opt.Ignore());
    }
}

🆚 Comparación con AutoMapper

Característica Quick.Mapper AutoMapper
API Sintaxis ✅ 100% Compatible
Perfiles con Constructor
ReverseMap
ForMember
BeforeMap/AfterMap
ConstructUsing
Dependency Injection
Validación
Rendimiento ⚡ Optimizado
Tamaño del paquete 📦 Ligero 📦 Más grande
Curva de aprendizaje ✅ Cero (si conoces AutoMapper)

Si ya conoces AutoMapper, puedes usar Quick.Mapper sin cambiar NADA de tu código. 🎉

🎓 Guía de Migración desde AutoMapper

Quick.Mapper tiene una API 100% compatible con AutoMapper. Para migrar:

  1. Cambia el package reference:

<PackageReference Include="AutoMapper" Version="X.X.X" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="X.X.X" />


<PackageReference Include="Quick.Mapper" Version="1.0.0" />
  1. Actualiza los usings:
// Antes
using AutoMapper;

// Después
using Quick.Mapper;
using Quick.Mapper.Configuration;
using Quick.Mapper.Profiles;
  1. ¡Listo! Tu código existente funcionará sin cambios. ✅

📝 Licencia

Este proyecto está bajo la Licencia MIT. Ver el archivo LICENSE para más detalles.

🤝 Contribuir

Las contribuciones son bienvenidas! Por favor:

  1. Fork el proyecto
  2. Crea una rama para tu feature (git checkout -b feature/AmazingFeature)
  3. Commit tus cambios (git commit -m 'Add some AmazingFeature')
  4. Push a la rama (git push origin feature/AmazingFeature)
  5. Abre un Pull Request

🙏 Agradecimientos

  • Inspirado en AutoMapper
  • Gracias a la comunidad .NET

📞 Soporte


⭐ Si te gusta Quick.Mapper, considera darle una estrella en GitHub!

Made with ❤️ for the .NET Community

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.0.1 215 10/17/2025
8.0.0 224 10/16/2025

Version 8.0.1 - Incluye metadata completa, README y documentación. API 100% compatible con AutoMapper.