Mlapper-Mapper 1.2.2

dotnet add package Mlapper-Mapper --version 1.2.2
                    
NuGet\Install-Package Mlapper-Mapper -Version 1.2.2
                    
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="Mlapper-Mapper" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mlapper-Mapper" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="Mlapper-Mapper" />
                    
Project file
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 Mlapper-Mapper --version 1.2.2
                    
#r "nuget: Mlapper-Mapper, 1.2.2"
                    
#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 Mlapper-Mapper@1.2.2
                    
#: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=Mlapper-Mapper&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=Mlapper-Mapper&version=1.2.2
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
1.2.2 129 6/8/2025
1.2.1 118 6/8/2025
1.1.1 124 6/7/2025
1.0.1 153 4/12/2025