Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twinify logo

Twinify

Object mapping made simple.

.NET Support .NET Support NuGet Version NuGet Downloads License: MIT

Twinify copies values from one object to another so you don't have to write that code by hand. Describe the shape of the mapping once, then call Map<T>() wherever you need it.

var dto = mapper.Map<UserDto>(user);

Install

dotnet add package Twinify
dotnet add package Twinify.DependencyInjection

Quick start

1. Describe your mapping in a profile:

public class UserProfile : MappingProfile
{
    public UserProfile()
    {
        CreateMap<User, UserDto>()
            .ForMember(d => d.FullName, opt => opt.MapFrom(s => $"{s.FirstName} {s.LastName}"))
            .ForMember(d => d.Password, opt => opt.Ignore());
    }
}

2. Register it:

builder.Services.AddTwinify(cfg =>
{
    cfg.AddProfile<UserProfile>();
});

3. Use it:

public class UserService(IMapper mapper)
{
    public UserDto GetUser(User user) => mapper.Map<UserDto>(user);
}

That's it - properties with matching names are copied automatically. Anything you want to customize (rename, compute, ignore, convert) gets a line in the profile.

What it handles for you

  • Auto-matching - properties with the same name copy across without any configuration.
  • Flattening - a destination property like AddressCity automatically picks up source.Address.City.
  • Nested objects and collections - lists, arrays, dictionaries, and nested objects map recursively.
  • Custom logic - ForMember, Ignore, Condition, MapFrom, BeforeMap/AfterMap, ConvertUsing, and more, for the cases that need more than a straight copy.
  • Constructors and records - Twinify works out how to construct your destination type, including types with only a parameterized constructor.
  • Explain<TSource, TDestination>() - prints exactly where every destination member's value comes from, for when a mapping doesn't do what you expected.

Packages

Package What it's for
Twinify.Abstractions The types you write against: IMapper, MappingProfile, CreateMap, etc.
Twinify The mapping engine that actually executes your maps.
Twinify.DependencyInjection AddTwinify(...) and friends, for ASP.NET Core / generic host apps.

About

Learn how to use Twinify for effortless DTO, entity, and object mapping in .NET with examples, tutorials, and best practices.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages