Mappah.Extensions
2.3.0
dotnet add package Mappah.Extensions --version 2.3.0
NuGet\Install-Package Mappah.Extensions -Version 2.3.0
<PackageReference Include="Mappah.Extensions" Version="2.3.0" />
<PackageVersion Include="Mappah.Extensions" Version="2.3.0" />
<PackageReference Include="Mappah.Extensions" />
paket add Mappah.Extensions --version 2.3.0
#r "nuget: Mappah.Extensions, 2.3.0"
#:package Mappah.Extensions@2.3.0
#addin nuget:?package=Mappah.Extensions&version=2.3.0
#tool nuget:?package=Mappah.Extensions&version=2.3.0
Mappah
Minimalist object-to-object mapper for .NET.
💡 Features
- Auto-mapping properties by name
- Custom property mapping with expressions (
For
) - Ignoring properties (
Skip()
) - Reverse mapping support (
WithReverse()
) - Nested mapping support (native, just configure both nested and parent entities)
- ASP.NET Core integration via
AddMappah()
- Optimized collectio mapping via
WithCollection()
🚀 Target Frameworks
- .NET 8.0 and higher
📦 Installation
Install via NuGet:
dotnet add package Mappah
If you want to integrate with ASP.NET Core Dependency Injection:
dotnet add package Mappah.Extensions
🚀 Quick Start
Define a one-way mapping:
MapperConfigurationBuilder.Create<User, UserDto>()
.For(dest => dest.FullName, src => src.FirstName + " " + src.LastName)
.Skip(dest => dest.Password);
Or you can use WithReverse() to configure mapping backwards:
MapperConfigurationBuilder.Create<User, UserDto>()
.For(dest => dest.FullName, src => src.FirstName + " " + src.LastName)
.Skip(dest => dest.Password)
.WithReverse()
.For(dest => dest.FirstName, src => src.FullName.Split(' ')[0])
.For(dest => dest.LastName, src => src.FullName.Split(' ')[1]);
Build the configuration after mapping definition:
MapperConfigurationBuilder.Build();
Use the mapper:
var mapper = new DefaultMapperResolver();
var user = new User { FirstName = "John", LastName = "Doe", Password = "123456" };
var userDto = mapper.Map<UserDto, User>(user);
// or implicitly
var anotherUserDto = mapper.Map<UserDto>(user);
// userDto.FullName == "John Doe"
// userDto.Password == null
🔧 Collection mapping optimization
Mappah supports nested and explisit mapping of collections It will recognize if mappable properties are collections automatically But you can improve performance if you explicitly configure what properties will be mapped as collections To do so you can use WithCollection(...)
MapperConfigurationBuilder.Create<TypeA, TypeB>()
.WithCollection(dest => dest.CollectionB, src => src.CollectionA);
This allows the expression tree builder to pre-compile mapping expression for your collection
🔧 ASP.NET Core Integration
builder.Services.AddMappah();
Inject IMapResolver
anywhere:
public class MyService
{
private readonly IMapResolver _mapper;
public MyService(IMapResolver mapper)
{
_mapper = mapper;
}
}
📝 License
Licensed under the MIT License.
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 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. |
-
net8.0
- Mappah (>= 2.3.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.