XForge.AutoMapper.Testing
0.23.0
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package XForge.AutoMapper.Testing --version 0.23.0
NuGet\Install-Package XForge.AutoMapper.Testing -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.Testing" 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.Testing" Version="0.23.0" />
<PackageReference Include="XForge.AutoMapper.Testing" />
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.Testing --version 0.23.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: XForge.AutoMapper.Testing, 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.Testing@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.Testing&version=0.23.0
#tool nuget:?package=XForge.AutoMapper.Testing&version=0.23.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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.
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]andGenerateReversefor 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 Projection —
ProjectToforIQueryable/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 (
CustomerAddressStreet→Customer.Address.Street) - Records & Init-only — Full support for C# records and init-only properties
- Collections — Automatic collection iteration and element mapping
- DI Integration — Optional
IServiceCollectionregistration via assembly scanning - Testable —
MapperAsserthelpers 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
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 | 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 is compatible. 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 is compatible. 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.
-
net10.0
- XForge.AutoMapper (>= 0.23.0)
- XForge.AutoMapper.Abstractions (>= 0.23.0)
-
net8.0
- XForge.AutoMapper (>= 0.23.0)
- XForge.AutoMapper.Abstractions (>= 0.23.0)
-
net9.0
- XForge.AutoMapper (>= 0.23.0)
- XForge.AutoMapper.Abstractions (>= 0.23.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.