AOTMapper 3.0.0

dotnet add package AOTMapper --version 3.0.0
                    
NuGet\Install-Package AOTMapper -Version 3.0.0
                    
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="AOTMapper" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AOTMapper" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AOTMapper" />
                    
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 AOTMapper --version 3.0.0
                    
#r "nuget: AOTMapper, 3.0.0"
                    
#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 AOTMapper@3.0.0
                    
#: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=AOTMapper&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AOTMapper&version=3.0.0
                    
Install as a Cake Tool

AOTMapper

AOTMapper is a high-performance, compile-time object mapping library that eliminates runtime reflection overhead by generating mapping code at build time using Roslyn source generators.

Features

  • Zero Runtime Reflection: All mapping code is generated at compile-time
  • High Performance: Benchmark results show comparable or better performance than manual mapping
  • Compile-Time Safety: Type mismatches and missing properties are caught at build time
  • Multiple Mapping Patterns: Support for classic, instance extension, and multi-parameter patterns
  • IDE Integration: Full IntelliSense support and code analysis
  • Missing Property Detection: Automatic warnings for unmapped properties with code fixes

Installation

Install the AOTMapper NuGet package to your project:

dotnet add package AOTMapper

Quick Start

1. Define Your Models

public class User 
{
    public string Name { get; set; }
    public int Age { get; set; }
    public string Email { get; set; }
}

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

2. Create Mapper Methods

AOTMapper supports three different mapping patterns:

Classic Pattern
public static class UserMappers
{
    [AOTMapperMethod]
    public static UserDto MapToDto(this IAOTMapper mapper, User input)
    {
        var output = new UserDto();
        output.Name = input.Name;
        output.Age = input.Age;
        output.Email = input.Email;
        return output;
    }
}
Instance Extension Pattern (Single Parameter)
public static class UserMappers
{
    [AOTMapperMethod]
    public static UserDto MapToDto(this User input)
    {
        var output = new UserDto();
        output.Name = input.Name;
        output.Age = input.Age;
        output.Email = input.Email;
        return output;
    }
}
Multi-Parameter Instance Extensions

For scenarios requiring additional parameters (these are not registered with the mapper but work as direct extension methods):

public static class UserMappers
{
    [AOTMapperMethod]
    public static UserDto MapToDto(this User input, string defaultEmail)
    {
        var output = new UserDto();
        output.Name = input.Name;
        output.Age = input.Age;
        output.Email = input.Email ?? defaultEmail;
        return output;
    }
}

3. Build and Use the Mapper

// Build the mapper (the extension method is auto-generated)
var mapper = new AOTMapperBuilder()
    .AddYourProjectName() // Auto-generated based on your assembly name
    .Build();

// Use the mapper
var user = new User { Name = "John", Age = 30, Email = "john@example.com" };

// Classic and single-parameter patterns work through the mapper
var dto = mapper.Map<UserDto>(user);

// Multi-parameter extensions work as direct extension methods
var dtoWithDefault = user.MapToDto("default@example.com");

Console.WriteLine(dto.Name); // John

Advanced Features

Missing Property Detection

AOTMapper automatically detects unmapped properties and provides warnings:

[AOTMapperMethod]
public static UserDto MapToDto(this User input)
{
    var output = new UserDto();
    output.Name = input.Name;
    // Warning: Property 'Age' is not mapped
    // Warning: Property 'Email' is not mapped
    return output;
}

Disabling Missing Property Validation

[AOTMapperMethod(disableMissingPropertiesDetection: true)]
public static UserDto MapToDto(this User input)
{
    var output = new UserDto();
    output.Name = input.Name;
    // No warnings will be generated
    return output;
}

Code Fixes

AOTMapper provides automatic code fixes for missing properties. When the analyzer detects unmapped properties, you can use the Quick Fix feature in your IDE to automatically add the missing property assignments.

How It Works

Source Generation

When you build your project, AOTMapper's source generator:

  1. Scans for methods marked with [AOTMapperMethod]
  2. Validates method signatures and property mappings
  3. Generates registration extension methods like AddYourAssemblyName()
  4. Creates optimized mapping code with zero runtime reflection

Generated Code Example

For a method like:

[AOTMapperMethod]
public static UserDto MapToDto(this User input) { /* ... */ }

AOTMapper generates:

public static AOTMapperBuilder AddYourProject(this AOTMapperBuilder builder)
{
    builder.AddMapper<User, UserDto>((mapper, input) => UserMappers.MapToDto(input));
    return builder;
}

Pattern Comparison

Pattern Registration Usage Best For
Classic ✅ Auto-registered mapper.Map<T>(input) Standard scenarios
Instance Extension ✅ Auto-registered mapper.Map<T>(input) or input.MapToDto() Fluent syntax preference
Multi-Parameter ❌ Not registered input.MapToDto(param1, param2) Complex scenarios with context

Performance

AOTMapper is designed for maximum performance:

  • Zero Reflection: All mapping logic is generated at compile-time
  • Direct Method Calls: Generated code uses direct method invocations
  • Minimal Overhead: Registration and lookup optimized for speed
  • Memory Efficient: No runtime code generation or dynamic assemblies

IDE Integration

AOTMapper provides rich IDE support:

  • IntelliSense: Full autocomplete for generated extension methods
  • Error Squiggles: Real-time validation of mapping methods
  • Quick Fixes: Automatic generation of missing property assignments
  • Go to Definition: Navigate from usage to mapper method definitions
There are no supported framework assets in this 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
3.0.0 95 8/13/2025
2.1.1 4,192 6/13/2022
2.1.0 479 6/13/2022
2.0.0 504 6/11/2022
2.0.0-preview1 322 6/9/2022
1.0.5 1,292 7/10/2019
1.0.4 848 7/10/2019
1.0.3 805 7/10/2019
1.0.2 762 7/9/2019
1.0.1 820 7/9/2019
1.0.0 793 7/8/2019

Updated author and basic package info