TacoMapper 1.0.1
dotnet add package TacoMapper --version 1.0.1
NuGet\Install-Package TacoMapper -Version 1.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="TacoMapper" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TacoMapper" Version="1.0.1" />
<PackageReference Include="TacoMapper" />
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 TacoMapper --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TacoMapper, 1.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 TacoMapper@1.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=TacoMapper&version=1.0.1
#tool nuget:?package=TacoMapper&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Taco Mapper
A very lightweight C# object mapper with a fluent API that supports basic mapping, conditional mapping, and combine mapping. The library is designed to be readable, small, and efficient.
Features
- 🌮 Basic Property Mapping - Auto-map properties with matching names and types
- 🌯 Custom Transformations - Transform values during mapping
- 🥙 Conditional Mapping - Map properties based on conditions
- 🌮 Combine Mapping - Combine multiple source properties into one destination property
- 🔥 Fluent API - Chain mapping configurations for readability
- 📦 Collection Support - Map collections of objects
- 🚫 Ignore Properties - Skip specific properties during mapping
- ⚡ Lightweight - Minimal dependencies and small footprint
Quick Start
Basic Auto-Mapping
// Simple mapping for properties with matching names and types
var personDto = ObjectMapper.Map<Person, PersonDto>(person);
Fluent API with Custom Mapping
var mapper = ObjectMapper.Create<Person, PersonDto>()
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.Email, src => src.Email)
.Map(dest => dest.Age, src => src.DateOfBirth, dob => DateTime.Now.Year - dob.Year)
.Map(dest => dest.Status, src => src.IsActive, active => active ? "Active" : "Inactive")
.Combine(dest => dest.FullName, src => $"{src.FirstName} {src.LastName}");
var result = mapper.MapFrom(person);
Conditional Mapping
var mapper = ObjectMapper.Create<Person, PersonDto>()
.Map(dest => dest.Id, src => src.Id)
.MapIf(dest => dest.SalaryFormatted,
src => src.Salary,
salary => $"${salary:N2}",
src => src.IsActive) // Only map salary if person is active
.Combine(dest => dest.FullName, src => $"{src.FirstName} {src.LastName}");
Combine Multiple Properties
var mapper = ObjectMapper.Create<Address, AddressDto>()
.Map(dest => dest.Street, src => src.Street)
.Map(dest => dest.City, src => src.City)
.Map(dest => dest.ZipCode, src => src.ZipCode)
.Combine(dest => dest.FormattedAddress,
src => $"{src.Street}, {src.City} {src.ZipCode}");
Ignore Properties
var mapper = ObjectMapper.Create<Person, PersonDto>()
.Map(dest => dest.Id, src => src.Id)
.Ignore(dest => dest.Email) // Skip email mapping
.Combine(dest => dest.FullName, src => $"{src.FirstName} {src.LastName}");
Collection Mapping
var people = new List<Person> { /* ... */ };
// Using 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
var simpleResults = ObjectMapper.Map<Person, PersonDto>(people);
API Reference
ObjectMapper Static Methods
Create<TSource, TDestination>()
- Creates a new mapper instanceMap<TSource, TDestination>(source)
- Simple auto-mapping for single objectMap<TSource, TDestination>(sources)
- Simple auto-mapping for collections
IMapper Interface
Map(dest, src)
- Basic property mappingMap(dest, src, transform)
- Property mapping with transformationMapIf(dest, src, condition)
- Conditional property mappingMapIf(dest, src, transform, condition)
- Conditional mapping with transformationCombine(dest, combineFunction)
- Combine multiple source propertiesIgnore(dest)
- Ignore a destination propertyMapFrom(source)
- Execute mapping on single objectMapFrom(sources)
- Execute mapping on collection
How It Works
The mapper uses:
- Reflection for auto-mapping properties with matching names and types
- Expression trees for fluent property selection
- Compiled delegates for efficient property access and transformations
- Dictionary-based caching for mapping configurations
- Clean architecture with organized core components
Performance Considerations
- Mappers are reusable - create once, use many times
- Compiled expressions provide good performance after first use
- Auto-mapping uses reflection, so explicit mapping is faster for hot paths
- Small memory footprint with minimal allocations
Requirements
- .NET 8.0 or later
- C# 12.0 language features
License
MIT License
Product | Versions 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.
-
net8.0
- No dependencies.
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 |
---|---|---|
1.0.1 | 141 | 6/23/2025 |
1.0.0 | 129 | 6/23/2025 |
1.0.0-pre6-20250623220433 | 130 | 6/23/2025 |
1.0.0-pre5-20250623214635 | 144 | 6/23/2025 |
1.0.0-pre18-20250716161720 | 102 | 7/16/2025 |
1.0.0-pre17-20250624191402 | 130 | 6/24/2025 |
1.0.0-pre15-20250624175451 | 130 | 6/24/2025 |
0.0.1 | 132 | 6/23/2025 |
See https://github.com/tavobarrientos/TacoMapper/releases for release notes