Twinify
A .NET library that copies values between C# objects.
Problem
Copying properties from one C# type to another by hand is repetitive, and it drifts when a property is renamed or added.
Context
Twinify is published on NuGet for .NET 8, 9, and 10. The usage guide is in the Twinify.Docs repository. A separate TwinifyBenchmarks repository holds benchmarks. This site does not republish those numbers.
Role
Author and maintainer.
Solution
Twinify turns a mapping into a compiled delegate. If property names match, it copies them with no profile. Profiles and attributes cover the exceptions: rename, compute, ignore, or convert. Twinify.DependencyInjection registers the mapper in ASP.NET Core. A source generator covers Native AOT, where runtime compilation is not available.
Architecture
Three packages. Twinify is the engine and includes the source generator. Twinify.Abstractions holds IMapper, MappingProfile, and the CreateMap/ForMember API, so a class library can declare profiles without referencing the engine. Twinify.DependencyInjection adds AddTwinify() to an ASP.NET Core or generic host.
Engineering decisions
- Matching property names map with no CreateMap call. Profiles are for the members that do not match.
- Abstractions are a separate package so profile code does not take a dependency on the engine.
- Native AOT uses a source generator. The readme states that ForMember and ConvertUsing are not generated for AOT, and attributes are the AOT path.
Challenges
Native AOT cannot compile expression trees at runtime. A pair that was not generated throws MappingNotFoundException. That split, JIT versus generated maps, is the constraint the package documents.
Implementation
In an ASP.NET Core app, register the mapper and inject IMapper. With no profiles, matching types map by name.
dotnet add package Twinify
dotnet add package Twinify.DependencyInjectionbuilder.Services.AddTwinify();
public class UserService(IMapper mapper)
{
public UserDto ToDto(User user) => mapper.Map<UserDto>(user);
}Security
The readme documents two ways to keep a value off the destination: an IgnoreMap attribute, or ForMember with Ignore. The stated example is a password field on a DTO.
Performance
Maps are expression-compiled delegates on JIT runtimes. Benchmark code lives in TwinifyBenchmarks. No benchmark figures are copied onto this site.
Technology
- C#
- .NET
- ASP.NET Core
Outcome
Published on NuGet as Twinify 1.1.0, with Twinify.Abstractions and Twinify.DependencyInjection. The NuGet listing reviewed for this page was updated on 14 September 2026.