NMapper 2.0.16-pre
See the version list below for details.
dotnet add package NMapper --version 2.0.16-pre
NuGet\Install-Package NMapper -Version 2.0.16-pre
<PackageReference Include="NMapper" Version="2.0.16-pre" />
<PackageVersion Include="NMapper" Version="2.0.16-pre" />
<PackageReference Include="NMapper" />
paket add NMapper --version 2.0.16-pre
#r "nuget: NMapper, 2.0.16-pre"
#:package NMapper@2.0.16-pre
#addin nuget:?package=NMapper&version=2.0.16-pre&prerelease
#tool nuget:?package=NMapper&version=2.0.16-pre&prerelease
NMapper
NMapper is a lightweight, explicit object mapping library for .NET. It favours clear, testable mapping code over configuration and conventions.
Key Features
- Explicit mapping classes written in plain C#
- One-way and two-way mappings.
- Supports nested mappings.
- Automatic mapping of collections and arrays.
- Clear compile-time errors instead of runtime surprises.
- No conventions, no reflection-based property mapping, no magic.
- Designed to use with dependency injection (Microsoft.Extensions.DependencyInjection).
Philosophy
Mapping is application logic. NMapper treats mappings as first-class code rather than configuration. Every mapping is explicit, discoverable, and refactor-safe.
NMapper intentionally avoids automatic property matching and hidden behavior in favor of clarity, control, and debuggability.
Download and Install NMapper
This library is available on NuGet: https://www.nuget.org/packages/NMapper/ Use the following command to install NMapper using the NuGet Package Manager Console:
PM> Install-Package NMapper
You can use this library in any .NET project which is compatible to .NET Standard 2.0 and higher.
API Usage
Define a Mapping
Mappings are defined as simple C# classes by implementing IMapping<TSource, TTarget>. This interface gives you the extra parameter IMappingContext which allows to run further mappings.
public class PersonMapping :
IMapping<Person, PersonDto>,
IMapping<PersonDto, Person>
{
public PersonDto Map(Person source) => new()
{
Id = source.Id,
Name = source.Name
};
public Person Map(PersonDto source) => new()
{
Id = source.Id,
Name = source.Name
};
}
Nested Mappings
If a mapping needs to delegate to other mappings, implement
IMappingWithContext<TSource, TTarget>.
public class OrderMapping : IMappingWithContext<Order, OrderDto>
{
public OrderDto Map(Order source, IMappingContext context) => new()
{
Id = source.Id,
Customer = context.Map<CustomerDto>(source.Customer)
};
}
Register Mappings
Mappings are typically registered via dependency injection.
services.AddMapping(options =>
{
options.MapperAssemblies = new[]
{
typeof(PersonMapping).Assembly
};
});
Perform Mappings
Create a new instance of Mapper or inject IMapper via dependency injection and use it to perform mappings.
var personDto = mapper.Map<PersonDto>(person);
Mapping Collections and Arrays
Collections and arrays are mapped automatically as long as an element mapping exists.
var personDtos = mapper.Map<IEnumerable<PersonDto>>(persons);
Exceptions
NMapper uses explicit, strongly typed exceptions to make mapping errors easy to diagnose. All exceptions are thrown at runtime and indicate configuration or mapping logic errors.
| Exception | Description |
|---|---|
| DuplicateMappingException | Thrown when more than one mapping is registered for the same source and target type. Each source → target pair must be unique. |
| MissingMappingException | Thrown when no mapping exists for the requested source and target type and no built-in primitive conversion applies. |
| MappingException | Thrown when an error occurs during execution of a mapping. This exception wraps the original exception and adds source type, target type, and mapping type information. |
| AggregateException | When multiple nested mappings fail during a single mapping operation, NMapper may throw an AggregateException containing one or more of the exceptions listed above. This behavior allows all mapping errors to be reported at once instead of failing on the first error. |
Thank You
A big thank you to all the people who have contributed to this project! If you find a bug or want to propose a new feature, feel free to open an issue on GitHub.
We'd also like to thank nabinked for leaving us the project name and working title NMapper.
| 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 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 is compatible. |
| .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
-
.NETStandard 2.1
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 |
|---|---|---|
| 2.2.0-pre | 130 | 4/2/2026 |
| 2.1.13 | 108 | 4/2/2026 |
| 2.1.11-pre | 99 | 4/2/2026 |
| 2.1.9-pre | 93 | 4/2/2026 |
| 2.1.8-pre | 101 | 3/30/2026 |
| 2.1.7-pre | 98 | 3/29/2026 |
| 2.1.6-pre | 95 | 3/29/2026 |
| 2.1.5-pre | 108 | 3/27/2026 |
| 2.1.4-pre | 99 | 3/27/2026 |
| 2.1.3-pre | 93 | 3/25/2026 |
| 2.1.2-pre | 109 | 2/5/2026 |
| 2.1.1-pre | 154 | 1/24/2026 |
| 2.1.0-pre | 109 | 1/24/2026 |
| 2.0.23 | 132 | 1/24/2026 |
| 2.0.21-pre | 111 | 1/22/2026 |
| 2.0.20-pre | 113 | 1/22/2026 |
| 2.0.19-pre | 115 | 1/15/2026 |
| 2.0.18-pre | 110 | 1/11/2026 |
| 2.0.17-pre | 110 | 1/11/2026 |
| 2.0.16-pre | 116 | 1/9/2026 |
1.0
- Initial release.