XForge.AutoMapper.Analyzers 0.23.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package XForge.AutoMapper.Analyzers --version 0.23.0
                    
NuGet\Install-Package XForge.AutoMapper.Analyzers -Version 0.23.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="XForge.AutoMapper.Analyzers" Version="0.23.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XForge.AutoMapper.Analyzers" Version="0.23.0" />
                    
Directory.Packages.props
<PackageReference Include="XForge.AutoMapper.Analyzers" />
                    
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 XForge.AutoMapper.Analyzers --version 0.23.0
                    
#r "nuget: XForge.AutoMapper.Analyzers, 0.23.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 XForge.AutoMapper.Analyzers@0.23.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=XForge.AutoMapper.Analyzers&version=0.23.0
                    
Install as a Cake Addin
#tool nuget:?package=XForge.AutoMapper.Analyzers&version=0.23.0
                    
Install as a Cake Tool

XForge.AutoMapper

<p align="center"> <img src="manual/assets/XForge.png" alt="XForge.AutoMapper" width="128" height="128" /> </p>

Source-generator-first .NET object mapping library — zero reflection, NativeAOT safe, Blazor WASM friendly.

NuGet NuGet Downloads CI License: MIT .NET

Quick Start

using XForge.AutoMapper;

// Option A: Explicit partial methods
[Mapper]
public partial class CustomerMapper
{
    public partial CustomerDto ToDto(Customer source);
}

// Option B: AutoMapper-style
[Mapper]
[Map(typeof(Customer), typeof(CustomerDto))]
[Map(typeof(Order), typeof(OrderDto))]
public partial class AppMapper { }

// Usage:
var mapper = new AppMapper();
CustomerDto dto = mapper.Map<CustomerDto>(customer);

// Via strongly-typed interface:
IMapper<Customer, CustomerDto> iMapper = mapper;
CustomerDto dto2 = iMapper.Map(customer);

Features

  • Source Generation — Primary code generation path, zero reflection on critical path
  • NativeAOT & Trimming — Fully compatible with AOT compilation and IL trimming
  • Blazor WASM — First-class support for WebAssembly scenarios
  • Compile-time Diagnostics — XAM-prefixed warnings and errors before runtime
  • AutoMapper-style API[Map<S,D>] attribute for class-level declarations
  • Open Generics Mapping — Generic mapper classes with closed-form generation per type pair
  • Multi-Source Mapping[MapFrom] for merging multiple sources into one destination
  • Reverse Mapping[MapReverse] and GenerateReverse for bidirectional mapping
  • Value Converters[ValueConverter] for property transformation during mapping
  • Value Resolvers[ResolveUsing] for computing destination values from the entire source object
  • Conditional Mapping[MapWhen] to map only when source property is non-null
  • Null Substitution[NullSubstitute] for fallback values on null source properties
  • Before/After Hooks[BeforeMap]/[AfterMap] for side effects and auditing
  • LINQ ProjectionProjectTo for IQueryable/EF Core-safe expression trees
  • Flattening — Automatic nested-to-flat property mapping via PascalCase matching
  • Unflattening — Automatic nested object construction from flat source properties, supports multi-level deep nesting (CustomerAddressStreetCustomer.Address.Street)
  • Records & Init-only — Full support for C# records and init-only properties
  • Collections — Automatic collection iteration and element mapping
  • DI Integration — Optional IServiceCollection registration via assembly scanning
  • TestableMapperAssert helpers for unit testing without DI container

Performance

Benchmarks on .NET 10.0, Windows 11, x64 RyuJIT AVX2. See full results.

Scenario XForge AutoMapper Mapster Mapperly Manual
Cold Start 14 ns 709,612 ns 25 ns 18 ns 14 ns
Simple Class 7.6 ns 61.7 ns 17.2 ns 8.1 ns 9.1 ns
Nested Object 17.6 ns 64.4 ns 39.2 ns 17.1 ns 33.6 ns
Record 9.4 ns 63.3 ns 19.8 ns 10.4 ns 8.5 ns
Enum 8.4 ns 66.6 ns 17.9 ns 8.4 ns 8.4 ns
Inheritance 13.0 ns 81.4 ns 28.5 ns 16.8 ns 19.0 ns
  • 50,000x faster cold start than AutoMapper (14 ns vs 710 μs)
  • 6-8x faster than AutoMapper in steady state
  • On par with Mapperly (both source-generated)
  • Zero extra allocations vs manual mapping
  • NativeAOT safe — no reflection, no runtime code emit
dotnet run --project benchmarks/XForge.AutoMapper.Benchmarks/XForge.AutoMapper.Benchmarks.csproj -c Release -- --filter "*" --job short --memory

Packages

Package NuGet Description
XForge.AutoMapper.Abstractions NuGet Contracts, attributes, and interfaces
XForge.AutoMapper NuGet Minimal runtime and mapper base
XForge.AutoMapper.SourceGeneration NuGet Roslyn incremental source generator
XForge.AutoMapper.Analyzers NuGet Roslyn analyzers and code fixes
XForge.AutoMapper.Queryable NuGet IQueryable projection support
XForge.AutoMapper.Extensions.DependencyInjection NuGet DI extensions and assembly scanning
XForge.AutoMapper.Testing NuGet Test helpers (MapperAssert)

Installation

dotnet add package XForge.AutoMapper
dotnet add package XForge.AutoMapper.SourceGeneration

Optional packages:

dotnet add package XForge.AutoMapper.Extensions.DependencyInjection
dotnet add package XForge.AutoMapper.Queryable
dotnet add package XForge.AutoMapper.Testing

Diagnostics

Compile-time diagnostics with the XAM prefix:

ID Severity Description
XAM001 Warning Target property has no matching source property
XAM002 Info Source property is not mapped to any target property
XAM003 Warning Cyclic mapping detected (A→B and B→A in same mapper)
XAM004 Error Invalid value converter type
XAM005 Error Ambiguous mapping hook (MapMethodName required)
XAM006 Error Invalid [MapWhen] source property
XAM007 Error Invalid [MapReverse] method reference
XAM008 Error [Map] attribute conflicts with existing partial method
XAM009 Warning Multi-source property conflict (incompatible types across sources)
XAM010 Error [Mapper] class must be partial
XAM011 Error Mapper method must be partial
XAM012 Warning Duplicate [MapProperty] target
XAM013 Warning Non-reversible flattening detected
XAM014 Error Invalid value resolver type
XAM015 Error Partial method in open generic mapper cannot be auto-implemented

Documentation

Complete enterprise-grade manual with examples from basic to advanced:

License

MIT

Product 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 was computed.  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. 
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
1.0.0-preview.1 32 5/21/2026
0.23.0 34 5/22/2026
0.22.0 35 5/22/2026
0.20.0 41 5/22/2026
0.19.0 38 5/22/2026
0.18.0 34 5/21/2026
0.17.0 43 5/21/2026
0.16.0 35 5/21/2026
0.15.0 36 5/21/2026
0.14.0 34 5/21/2026