Mlapper-Mapper
1.2.2
dotnet add package Mlapper-Mapper --version 1.2.2
NuGet\Install-Package Mlapper-Mapper -Version 1.2.2
<PackageReference Include="Mlapper-Mapper" Version="1.2.2" />
<PackageVersion Include="Mlapper-Mapper" Version="1.2.2" />
<PackageReference Include="Mlapper-Mapper" />
paket add Mlapper-Mapper --version 1.2.2
#r "nuget: Mlapper-Mapper, 1.2.2"
#:package Mlapper-Mapper@1.2.2
#addin nuget:?package=Mlapper-Mapper&version=1.2.2
#tool nuget:?package=Mlapper-Mapper&version=1.2.2
Mlapper-Mapper
A lightweight object-to-object mapping library for .NET applications.
Features
- Simple configuration API
- Automatic property discovery and mapping
- Custom property mapping with lambda expressions
- Type conversion support
- Fluent configuration interface
- Reverse mapping support (fluent chaining)
- Conditional and profile mapping
Installation
dotnet add package Mlapper-Mapper
Basic Usage
// Set up your mapping configuration
var config = new MapperConfiguration();
// Create map with automatic property discovery
config.CreateMap<CustomerDto, Customer>();
// Add custom property mapping
config.ForMember<CustomerDto, Customer>(
dest => dest.FullName,
src => src.FirstName + " " + src.LastName
);
// Create mapper
var mapper = config.CreateMapper();
// Map objects
var customerDto = new CustomerDto { FirstName = "John", LastName = "Doe", Age = 30 };
var customer = mapper.Map<CustomerDto, Customer>(customerDto);
// Map to existing object
var existingCustomer = new Customer();
mapper.Map(customerDto, existingCustomer);
For your web projects, add it as a service to your Program file
builder.Services.AddSingleton(sp =>
{
var config = new MapperConfiguration();
config.CreateMap<ProductDto, Product>();
return config.CreateMapper();
});
Advanced Usage
Null Handling
The library handles null values appropriately:
// Returns default(Customer) (null for reference types)
var result = mapper.Map<CustomerDto, Customer>(null);
// Returns the existing destination object
var keptObject = mapper.Map(null, existingCustomer);
Type Conversions
Automatic type conversions are supported for compatible types:
- Numeric conversions (int → long, float → double)
- String to numeric conversions
- Numeric to string conversions
- Any assignment-compatible types
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details
Added MappingExpression Class
Created a new MappingExpression<TSource, TDestination> class that enables fluent API chaining
Implemented the ReverseMap() method that creates a reverse mapping and returns a new expression for the reverse direction
Added support for ForMember() to configure custom mappings
Created Comprehensive Test Cases:
FluentReverseMappingTests.cs: Tests the fluent API for reverse mapping
Basic bidirectional mapping with ReverseMap()
Custom mappings in both directions
Added Profile Support:
ProfileWithFluentTests.cs: Shows how to use fluent reverse mapping in profiles
Demonstrates creating mappings with custom property configurations
Helper Classes:
Added ReverseConfiguration.cs with utility methods for reverse mapping
The tests now pass successfully, showing that the fluent reverse mapping functionality works correctly. This implementation follows AutoMapper's pattern where you can chain method calls:
config.CreateMap<SourceClass, DestinationClass>()
.ForMember(dest => dest.FullName, src => $"{src.Name} {src.Description}")
.ReverseMap();
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
- 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.