Fjeller.SimpleMapper 1.0.0

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

SimpleMapper for .NET

A fast, lightweight object-to-object mapper for .NET with built-in dependency injection support and expression tree compilation for optimal performance.

NuGet Version NuGet Downloads License: MIT

Why SimpleMapper?

  • πŸš€ Fast: Uses compiled expression trees - up to 6x faster than reflection-based mapping
  • 🎯 Simple: Clean, intuitive API - map objects in one line
  • πŸ’‰ DI Ready: First-class ASP.NET Core integration with assembly scanning
  • πŸ“¦ Lightweight: Minimal dependencies, focused feature set
  • βœ… Type-Safe: Compile-time checking with generic methods
  • πŸ”§ Flexible: Support for collections, nested objects, and custom transformations

Performance at a Glance

Simple Object Mapping:   80 ns  (1.8x faster than baseline)
Complex Object Mapping:  90 ns  (6.2x faster than baseline)
Memory Efficient:        Singleton with compiled expression caching

Quick Start

Installation

dotnet add package Fjeller.SimpleMapper

Basic Usage

// 1. Define your models
public class User
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
}

public class UserDto
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
}

// 2. Create a mapping profile
public class UserMappingProfile : MappingProfile
{
    public UserMappingProfile()
    {
        CreateMap<User, UserDto>();
    }
}

// 3. Register in dependency injection
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSimpleMapper(typeof(Program).Assembly);

// 4. Inject and use
public class UsersController : ControllerBase
{
    private readonly ISimpleMapper _mapper;
    
    public UsersController(ISimpleMapper mapper)
    {
        _mapper = mapper;
    }
    
    [HttpGet("{id}")]
    public ActionResult<UserDto> GetUser(int id)
    {
        User user = GetUserFromDatabase(id);
        UserDto dto = _mapper.Map<User, UserDto>(user);
        return Ok(dto);
    }
}

That's it! You're mapping objects in production-ready code.

Key Features

Object-to-Object Mapping

Map between any two compatible types with automatic property matching by name and type.

Custom Property Mapping

CreateMap<User, UserDto>()
    .ForMember(dest => dest.FullName, 
        opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"))
    .ForMember(dest => dest.Status, 
        opt => opt.MapFrom(src => src.IsActive ? "Active" : "Inactive"));

Dependency Injection

// Assembly scanning - automatic profile discovery
builder.Services.AddSimpleMapper(typeof(Program).Assembly);

// Explicit profiles
builder.Services.AddSimpleMapper(new UserProfile(), new ProductProfile());

// Configuration options
builder.Services.AddSimpleMapper(options =>
{
    options.AddProfiles(typeof(Program).Assembly);
});

Collection Mapping

IEnumerable<User> users = GetUsers();
IEnumerable<UserDto> dtos = _mapper.Map<User, UserDto>(users);

Property Ignoring

CreateMap<User, UserDto>()
    .IgnoreMember(x => x.Password)
    .IgnoreMember(x => x.InternalId);

After-Mapping Actions

CreateMap<CreateUserDto, User>()
    .ExecuteAfterMapping((src, dest) =>
    {
        dest.CreatedAt = DateTime.UtcNow;
        dest.IsActive = true;
    });

Compiled Expression Trees

SimpleMapper compiles mappings to IL code at runtime, eliminating reflection overhead for near-manual mapping performance.

Documentation

πŸ“– Learning Path

New to SimpleMapper? Start here:

πŸ”§ How-to Guides

Solve specific problems:

πŸ“š Reference

Look up specific details:

πŸ’‘ Understanding SimpleMapper

Deep dive into concepts:

πŸ—ΊοΈ Navigation

Requirements

  • .NET 9 or later
  • C# 12 or later

Note: The library targets .NET 9 and is fully compatible with both .NET 9 and .NET 10 runtimes. .NET 9 was chosen as the target framework to ensure maximum compatibility with current ecosystem packages.

Supported Scenarios

βœ… ASP.NET Core Web API
βœ… ASP.NET Core MVC
βœ… Blazor Server
βœ… Blazor WebAssembly
βœ… Minimal APIs
βœ… Console Applications
βœ… Desktop Applications

Compatible Types

  • Primitive types (int, string, bool, etc.)
  • Value types (decimal, DateTime, Guid, etc.)
  • Complex objects (classes with properties)
  • Collections (List<T>, T[], IEnumerable<T>)
  • Nested objects (deep mapping)

Examples

Custom Property Mappings

// Map from different property names
CreateMap<User, UserDto>()
    .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.DisplayName));

// Computed values
CreateMap<Product, ProductDto>()
    .ForMember(dest => dest.FinalPrice, 
        opt => opt.MapFrom(src => src.Price * (1 - src.DiscountPercentage / 100m)));

// Flattening nested objects
CreateMap<Order, OrderDto>()
    .ForMember(dest => dest.CustomerName, 
        opt => opt.MapFrom(src => $"{src.Customer.FirstName} {src.Customer.LastName}"));

Map with Existing Destination

User user = GetUser();
UserDto existingDto = new UserDto();
_mapper.Map(user, existingDto); // Updates existing object

Map Collections

List<Product> products = GetProducts();
List<ProductDto> dtos = _mapper.Map<Product, ProductDto>(products).ToList();

Dynamic Source Type

object source = GetEntity(); // Runtime type
UserDto dto = _mapper.Map<UserDto>(source);

Ignore Multiple Properties

CreateMap<User, UserDto>()
    .IgnoreMembers(
        nameof(User.Password),
        nameof(User.PasswordHash),
        nameof(User.SecurityStamp)
    );

Performance Tips

  1. Use Assembly Scanning: Profiles are discovered automatically at startup
  2. Singleton Lifetime: Default registration is optimal - don't change it
  3. Compiled Expressions: First mapping compiles (~5-10ms), subsequent mappings are fast (~80-90ns)
  4. Collections: Deep mapping of complex collection elements uses reflection (acceptable trade-off for flexibility)

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Follow existing code style
  4. Include tests for new features
  5. Submit a pull request

License

[Specify your license here]

Support


Built with ❀️ for the .NET community

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.0 92 3/8/2026
1.0.0-alpha-3 295 12/18/2025
1.0.0-alpha-2 275 12/17/2025
1.0.0-alpha-1 134 12/6/2025

Initial release of SimpleMapper with compiled expression trees, dependency injection support, and collection mapping.