Mapsicle 1.0.4
See the version list below for details.
dotnet add package Mapsicle --version 1.0.4
NuGet\Install-Package Mapsicle -Version 1.0.4
<PackageReference Include="Mapsicle" Version="1.0.4" />
<PackageVersion Include="Mapsicle" Version="1.0.4" />
<PackageReference Include="Mapsicle" />
paket add Mapsicle --version 1.0.4
#r "nuget: Mapsicle, 1.0.4"
#:package Mapsicle@1.0.4
#addin nuget:?package=Mapsicle&version=1.0.4
#tool nuget:?package=Mapsicle&version=1.0.4
Mapsicle π¦
Mapsicle is a high-performance, zero-dependency object mapper for .NET. It uses compiled Expression Trees to achieve near-native mapping speed with zero configuration required.
"The fastest mapping is the one you don't have to configure."
π Why Switch from AutoMapper?
β οΈ AutoMapper is now commercial software. As of version 13+, AutoMapper requires a paid license for commercial use. Mapsicle remains 100% free and MIT licensed forever.
| Feature | Mapsicle | AutoMapper |
|---|---|---|
| License | MIT (Free Forever) | Commercial (Paid) |
| Dependencies | 0 (Zero) | 5+ packages |
| Setup Required | None | Profiles, CreateMap, DI |
| Binary Size | ~15KB | ~500KB+ |
| Flattening | Built-in by convention | Requires ForMember config |
| Case Sensitivity | Case-insensitive | Configurable |
Real Talk: When to Use What
β Use Mapsicle when:
- You want zero configuration complexity
- You want to avoid commercial licensing fees
- Performance matters (APIs, high-throughput services)
- You're mapping simple-to-moderate object graphs
- You hate NuGet dependency bloat
β οΈ Use AutoMapper when:
- You need complex
ForMemberlogic with external dependencies - You're deeply invested in AutoMapper's ecosystem and have a commercial license
π Benchmark Results
Real benchmarks using BenchmarkDotNet on Apple M1, .NET 8.0:
| Scenario | Manual | Mapsicle | AutoMapper | Winner |
|---|---|---|---|---|
| Single Object | 31 ns | 59 ns | 72 ns | π₯ Mapsicle |
| Flattening | 14 ns | 29 ns | 56 ns | π₯ Mapsicle (2x faster!) |
| Collection (100) | 3.5 ΞΌs | 7.0 ΞΌs | 4.0 ΞΌs | AutoMapper |
Key Insights:
- Single object mapping: Mapsicle is 22% faster than AutoMapper
- Flattening: Mapsicle is 48% faster than AutoMapper (no config needed!)
- Cold start: ~284ΞΌs for first mapping (expression compilation)
- Memory: Same allocation as AutoMapper (120 bytes for single object)
Run benchmarks yourself:
cd tests/Mapsicle.Benchmarks
dotnet run -c Release
π¦ Installation
dotnet add package Mapsicle
That's it. No DI registration, no profiles, no configuration.
β‘ Quick Start
Basic Mapping
using Mapsicle;
var user = new User { Id = 1, Name = "Alice", Email = "alice@mail.com" };
// One line. That's it.
UserDto dto = user.MapTo<UserDto>();
Collection Mapping
var users = new List<User> { new() { Name = "Alice" }, new() { Name = "Bob" } };
// Direct List<T> result
List<UserDto> dtos = users.MapTo<UserDto>();
// Or as an array
UserDto[] array = users.MapToArray<UserDto>();
Map to Existing Object
var existing = new UserDto { Id = 1, Name = "Old", Email = "keep@me.com" };
var source = new User { Id = 1, Name = "New" };
source.Map(existing);
// existing.Name = "New", existing.Email = "keep@me.com" (preserved)
π Features
1. Automatic Flattening
No configuration needed. Just follow the naming convention:
public class Order { public Customer Customer { get; set; } }
public class Customer { public string Email { get; set; } }
// Destination DTO
public class OrderDto
{
public string CustomerEmail { get; set; } // Auto-mapped from Customer.Email!
}
var dto = order.MapTo<OrderDto>(); // CustomerEmail is populated automatically
2. Attribute-Based Configuration
public class UserDto
{
[MapFrom("UserName")] // Map from different property name
public string Name { get; set; }
[IgnoreMap] // Never mapped
public string Password { get; set; } = "NOT_MAPPED";
}
3. Dictionary Mapping
// Object to Dictionary
var dict = user.ToDictionary();
// { "Id": 1, "Name": "Alice", "Email": "alice@mail.com" }
// Dictionary to Object
var restored = dict.MapTo<User>();
4. Smart Type Coercion
| Source β Destination | Supported |
|---|---|
string β string |
β |
int β string |
β (via ToString) |
Enum β int |
β |
int β int? |
β |
int? β int |
β (default if null) |
ClassA β ClassB |
β (recursive mapping) |
List<A> β List<B> |
β |
IEnumerable β T[] |
β |
5. Record & Immutable Type Support
public record UserRecord(int Id, string Name);
var rec = source.MapTo<UserRecord>(); // Works via constructor
6. Cache Management
var info = Mapper.CacheInfo(); // { MapToEntries: 5, Total: 5 }
Mapper.ClearCache(); // Reset for testing
π§ Migration from AutoMapper
Before (AutoMapper)
// Startup.cs
services.AddAutoMapper(typeof(MappingProfile));
// MappingProfile.cs
public class MappingProfile : Profile
{
public MappingProfile()
{
CreateMap<User, UserDto>();
CreateMap<Order, OrderDto>()
.ForMember(d => d.CustomerEmail, opt => opt.MapFrom(s => s.Customer.Email));
}
}
// Usage
var dto = _mapper.Map<UserDto>(user);
After (Mapsicle)
// No startup config needed!
// Usage
var dto = user.MapTo<UserDto>();
// Flattening works automatically with naming convention
// Order.Customer.Email β OrderDto.CustomerEmail β
β οΈ Limitations
- Circular References: Not supported (will cause
StackOverflowException) - Complex Resolvers: No
ForMemberwith custom logicβuse[MapFrom]for simple cases - Deep Customization: If you need per-field transformation logic, write it manually
π Project Structure
Mapsicle/
βββ src/Mapsicle/ # Core library (~400 lines)
βββ tests/
βββ Mapsicle.Tests/ # 56+ unit tests
βββ Mapsicle.Benchmarks/ # Performance benchmarks
π€ Contributing
PRs welcome! Areas for contribution:
- Performance optimizations
- Additional type coercion scenarios
- Documentation improvements
π License
MIT License Β© Arnel Isiderio Robles
<p align="center"> <strong>Stop configuring. Start mapping.</strong><br> <em>Free forever. Zero dependencies. Pure performance.</em> </p>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Mapsicle:
| Package | Downloads |
|---|---|
|
Mapsicle.Fluent
Fluent configuration API for Mapsicle. Adds expression-based mapping, ForMember, Ignore, Condition, and configuration validation. |
|
|
Mapsicle.EntityFramework
Entity Framework Core integration for Mapsicle. Adds ProjectTo<T>() for IQueryable projections that translate to SQL. |
|
|
Mapsicle.Dapper
Dapper integration for Mapsicle - Bridge Dapper query results to mapped DTOs with fluent extensions |
|
|
Mapsicle.Serilog
Serilog integration for Mapsicle - Structured logging for mapping operations with performance tracking |
GitHub repositories
This package is not used by any popular GitHub repositories.