A lightweight, fast, and fully open-source object mapper (Mapster and AutoMapper alternative) for .NET that lets you map objects between types — including complex types and collections — with just one line of code (Mapping Example: entity.MapTo MyDto ()).
$ dotnet add package CompactMapper
CompactMapper is a lightweight, fast, and fully open-source object mapper for .NET that lets you map objects between types — including complex types and collections — with just one line of code.
🟢 No dependencies. No profiles. No configuration. Just pure mapping.
🔄 An open-source alternative to AutoMapper, which is now commercially licensed.Created by Hoskes
AutoMapper is an industry-standard library for object mapping in .NET — but starting from version 12, AutoMapper is no longer free for commercial use under its new license.
CompactMapper is:
# Using Package Manager Console
Install-Package CompactMapper
# Using .NET CLI
dotnet add package CompactMapper
# Using PackageReference in .csproj file
<PackageReference Include="CompactMapper" Version="1.0.1" />
After installing, add the namespace in your code files:
using CompactMapper;
Copy the CompactMapperExtension class into your project.
var customerDto = customer.MapTo<CustomerDto>();
var dto = order.MapTo<OrderDto>(); // Will also map order.Customer, order.Items, etc.
List<CustomerDto> customerDtos = customers.MapTo<List<CustomerDto>>();
Works for List<T>, IEnumerable<T>, T[], etc.
CompactMapperExtension.AddCustomMapping<Customer, CustomerDto>((src, dest) =>
{
dest.FullName = $"{src.FirstName} {src.LastName}";
});
var dto = user.MapTo<UserDto>(valueTransformer: (prop, value) =>
{
if (prop == "Email" && value is string email)
return email.ToLowerInvariant();
return value;
});
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
public List<Order> Orders { get; set; }
}
public class Address
{
public string Street { get; set; }
}
public class CustomerDto
{
public int Id { get; set; }
public string Name { get; set; }
public AddressDto Address { get; set; }
public List<OrderDto> Orders { get; set; }
}
public class AddressDto
{
public string Street { get; set; }
}
var customerDto = customer.MapTo<CustomerDto>();
No config, no fuss — deeply nested and collections mapped out of the box!
| Feature | AutoMapper | CompactMapper |
|---|---|---|
| Free for commercial use | ❌ (v12+) | ✅ Always |
| Configuration required | ✅ Yes | ❌ No |
| Profiles and Setup | ✅ Required | ❌ Not Needed |
| Collection Support | ✅ Yes | ✅ Yes |
| Nested Object Mapping | ✅ Yes | ✅ Yes |
| Custom Actions | ✅ Yes | ✅ Yes |
| Lightweight | ❌ Heavy at times | ✅ One class only |
MethodInfo.MakeGenericMethodIEnumerable<> interfacesCompactMapperDictionary<string, object> ↔ POCO)MIT License – free to use for personal and commercial projects.
Want to help improve CompactMapper? PRs are welcome!
If you'd like to add features or extensions (like flattening or reverse mapping), feel free to fork and contribute.
Feel free to open an issue or reach out if you use CompactMapper in your project — we'd love to hear how it's helping!