Azka.ObjectMapper 10.0.0-alpha5

This is a prerelease version of Azka.ObjectMapper.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Azka.ObjectMapper --version 10.0.0-alpha5
                    
NuGet\Install-Package Azka.ObjectMapper -Version 10.0.0-alpha5
                    
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="Azka.ObjectMapper" Version="10.0.0-alpha5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Azka.ObjectMapper" Version="10.0.0-alpha5" />
                    
Directory.Packages.props
<PackageReference Include="Azka.ObjectMapper" />
                    
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 Azka.ObjectMapper --version 10.0.0-alpha5
                    
#r "nuget: Azka.ObjectMapper, 10.0.0-alpha5"
                    
#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 Azka.ObjectMapper@10.0.0-alpha5
                    
#: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=Azka.ObjectMapper&version=10.0.0-alpha5&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Azka.ObjectMapper&version=10.0.0-alpha5&prerelease
                    
Install as a Cake Tool

Azka.ObjectMapper

NuGet .NET

Azka.ObjectMapper is a lightweight object mapping library for .NET, designed to map data between classes (for example, Entity to DTO) using profile-based configuration.

Features

  • Object mapping TSource -> TDestination.
  • Collection mapping IEnumerable<TSource> -> IEnumerable<TDestination>.
  • Custom member mapping with ForMember(...).
  • Ignore source members with Ignore(...).
  • Nested object mapping support (when profiles exist).
  • Nested collection mapping support.
  • Integration with Microsoft.Extensions.DependencyInjection.

Installation

dotnet add package Azka.ObjectMapper

Quick Start

1. Create models

public class User
{
    public Guid Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
    public DateTime CreatedAt { get; set; }
}

public class UserDto
{
    public Guid Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
    public long CreatedAtUnix { get; set; }
}

2. Create a mapping profile

using Azka.ObjectMapper;

public class UserMapProfile : ObjectMapProfile
{
    public UserMapProfile()
    {
        CreateMap<User, UserDto>()
            .ForMember(dest => dest.CreatedAtUnix, src =>
                new DateTimeOffset(src.CreatedAt).ToUnixTimeSeconds());
    }
}

3. Register in DI

Option A - register a profile instance:

using Azka.ObjectMapper;

builder.Services.AddObjectMapper(new UserMapProfile());

Option B - scan profiles from assembly:

using System.Reflection;
using Azka.ObjectMapper;

builder.Services.AddObjectMapper(Assembly.GetExecutingAssembly());

4. Use in service/controller

using Azka.ObjectMapper;

public class UsersService
{
    private readonly IObjectMapper _mapper;

    public UsersService(IObjectMapper mapper)
    {
        _mapper = mapper;
    }

    public UserDto GetDto(User user)
    {
        return _mapper.Map<User, UserDto>(user);
    }

    public IEnumerable<UserDto> GetDtos(IEnumerable<User> users)
    {
        return _mapper.Map<User, UserDto>(users);
    }
}

Mapping Configuration

ForMember (custom destination member)

CreateMap<User, UserDto>()
    .ForMember(dest => dest.Name, src => $"[USER] {src.Name}");

Ignore (ignore source member)

CreateMap<User, UserDto>()
    .Ignore(src => src.Email);

Nested Mapping

If a property is a complex object or a collection of complex objects, profiles for child types must also be available.

public class Address
{
    public string City { get; set; } = string.Empty;
}

public class AddressDto
{
    public string City { get; set; } = string.Empty;
}

public class User
{
    public Address Address { get; set; } = new();
}

public class UserDto
{
    public AddressDto Address { get; set; } = new();
}

public class UserMapProfile : ObjectMapProfile
{
    public UserMapProfile()
    {
        CreateMap<Address, AddressDto>();
        CreateMap<User, UserDto>();
    }
}

API Summary

  • IObjectMapper.Map<T, U>(T obj) maps a single object to destination type.
  • IObjectMapper.Map<T, U>(IEnumerable<T> listOfObjects) maps an object collection to destination collection type.
  • MapProfile<T, U>.ForMember(...) defines custom mapping for a destination member.
  • MapProfile<T, U>.Ignore(...) ignores a source member.

Important Notes

  • Destination type must have a default constructor.
  • Mapping only works when a CreateMap<T, U>() profile exists.
  • For nested types, nested profiles are also required.
  • If a mapping profile is not found, mapper throws InvalidOperationException.

Requirements

License

See LICENSE.txt.

Product Compatible and additional computed target framework versions.
.NET 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
10.0.0-rc.4 50 11/9/2026
10.0.0-rc.3 70 11/7/2026
10.0.0-rc.2 67 10/27/2026
10.0.0-rc.1 116 6/30/2026
10.0.0-alpha6 92 6/20/2026
10.0.0-alpha5 102 3/16/2026
10.0.0-alpha.9 91 6/25/2026
10.0.0-alpha.8 90 6/25/2026
10.0.0-alpha.7 99 6/25/2026

Initial release of Azka.ObjectMapper
     - Object Mapper