Mappy.dotNet
4.2.0
dotnet add package Mappy.dotNet --version 4.2.0
NuGet\Install-Package Mappy.dotNet -Version 4.2.0
<PackageReference Include="Mappy.dotNet" Version="4.2.0" />
<PackageVersion Include="Mappy.dotNet" Version="4.2.0" />
<PackageReference Include="Mappy.dotNet" />
paket add Mappy.dotNet --version 4.2.0
#r "nuget: Mappy.dotNet, 4.2.0"
#:package Mappy.dotNet@4.2.0
#addin nuget:?package=Mappy.dotNet&version=4.2.0
#tool nuget:?package=Mappy.dotNet&version=4.2.0
🍁 Mappy - Object Mapper
Mappy is a lightweight, convention-first object mapper for .NET with zero external runtime dependencies.
It keeps the common case simple:
var dto = entity.Map<EntityDto>();
Mappy focuses on predictable mapping, cached mapping plans, compiled property accessors, nested objects, collections, positional records and immutable constructor types, circular and shared-reference tracking, explicit converters, and in-place updates.
Why Mappy?
- Zero mandatory configuration—convention mapping works out of the box
- Cached mapping plans per source, destination, and member visibility combination
- Compiled property getters and setters
- Nested object and collection/array mapping (
List<T>,HashSet<T>, arrays, and compatible collection interfaces) - Constructor and positional
recordmapping, including unmatched/extra parameters - Circular and shared-reference preservation across graphs and collections
- Strongly typed and string-based property rename and ignore rules
- Explicit type converters plus enum and compatible numeric conversions
MapTofor updating existing instances andcustomMapping/withfor post-map enrichment- Detailed
MappingExceptiondiagnostics (SourceType,DestinationType,MemberName) - Targets
netstandard2.0andnet10.0with no external runtime dependencies
Installation
dotnet add package Mappy.dotNet --version 4.2.0
Basic Mapping
Properties with matching names (case-insensitive) and compatible types are mapped automatically:
var source = new User
{
Id = 1,
Name = "Manoj",
Email = "manoj@example.com"
};
var dto = source.Map<UserDto>();
Nested Mapping
Mappy recursively maps compatible nested objects:
Order
└── Customer
↓
OrderDto
└── CustomerDto
var dto = order.Map<OrderDto>();
Collections
Map sequences into List<T>, arrays, HashSet<T>, or compatible collection interfaces:
var result = users.MapCollection<UserDto>();
UserDto[] array = users.MapCollection<UserDto>().ToArray();
In Mappy 4.2, MapCollection and MapCollectionAsync share a single mapping context across items by default so shared references across elements preserve their mapped identity (handleCircularReferences: false disables this if needed).
Renaming and Ignoring Properties
Use strongly typed expressions when property names differ:
var config = new MappingConfiguration()
.Map<User, UserDto>(
source => source.FullName,
destination => destination.Name)
.Ignore<User, UserDto>(source => source.PasswordHash);
var dto = user.Map<UserDto>(config: config);
String-based configuration methods are also supported:
var config = new MappingConfiguration();
config.AddPropertyMapping(typeof(User), typeof(UserDto), "FullName", "Name");
config.ExcludeProperty(typeof(User), typeof(UserDto), "PasswordHash");
Explicit Converters and Conversions
Register custom type converters when you need explicit transformation logic:
var config = new MappingConfiguration()
.AddConverter<Guid, string>(value => value.ToString("N"));
var dto = entity.Map<EntityDto>(config: config);
Mappy also supports enum-to-string, string-to-enum, enum-to-primitive, DateOnly / TimeOnly, and compatible numeric conversions while throwing MappingException on incompatible types instead of silently guessing.
Records, Constructors, and Post-Map Enrichment
Mappy matches constructor parameters by name for immutable classes and positional record types without requiring a parameterless constructor:
public sealed record ItemResponse(
string Id,
string Code,
string Name,
decimal AvailableQuantity)
{
public ItemResponse() : this(string.Empty, string.Empty, string.Empty, 0m)
{
}
}
When a destination has extra fields not present on the source (such as AvailableQuantity), they default cleanly and can be populated via customMapping (for mutable/settable properties) or a with expression (for init-only record properties):
// With customMapping callback
var dto = item.Map<ItemResponse>(
customMapping: r => r.AvailableQuantity = availableQty);
// Or with a 'with' expression on init-only record members
var immutableDto = item.Map<ItemResponse>() with { AvailableQuantity = availableQty };
Mapping into an Existing Object
Update an existing destination instance with MapTo:
request.MapTo(
entity,
options: new MappingOptions
{
IgnoreNullValues = true
});
Setting IgnoreNullValues = true leaves existing destination properties untouched when source values are null—useful for partial/PATCH updates.
Circular References and Private Properties
Object identity tracking is enabled by default via MappingOptions.PreserveReferences:
Parent
└── Child
└── Parent
var result = source.Map<Destination>();
bool isSameRoot = ReferenceEquals(result, result.Child.Parent); // true
Non-public instance properties are included by default for backward compatibility and can be toggled via MappingOptions:
var options = new MappingOptions
{
IncludeNonPublicProperties = false,
PreserveReferences = true
};
Asynchronous Custom Mapping
Core mapping runs synchronously. Use MapAsync or MapCollectionAsync when your post-mapping enrichment requires asynchronous calls:
var dto = await source.MapAsync<UserDto>(async destination =>
{
destination.DisplayName = await GetDisplayNameAsync(source.Id);
});
var list = await users.MapCollectionAsync<UserDto>(async destination =>
{
destination.DisplayName = await GetDisplayNameAsync(destination.Id);
});
Performance and Design Goals
Mappy builds and caches mapping plans with compiled expression getters and setters on first use so repeated mappings avoid per-item reflection overhead:
Source + Destination + Visibility
↓
MappingPlan
↓
Compiled Getters / Setters
↓
Cached for Reuse
Mappy intentionally avoids:
- DI containers or global service locators
- Heavy configuration DSLs
- Source generators or external runtime dependencies
- Silent, arbitrary type coercion
Target Frameworks
.NET Standard 2.0(netstandard2.0).NET 10(net10.0)
License
Mappy is released under the MIT License.
| 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 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. |
| .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. |
-
.NETStandard 2.0
- No dependencies.
-
net10.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.
Mappy 4.2.0 shares mapping context across collection mappings, improves netstandard2.0 compatibility, and refines enum, numeric, and record constructor mapping