Twinify 1.0.2
dotnet add package Twinify --version 1.0.2
NuGet\Install-Package Twinify -Version 1.0.2
<PackageReference Include="Twinify" Version="1.0.2" />
<PackageVersion Include="Twinify" Version="1.0.2" />
<PackageReference Include="Twinify" />
paket add Twinify --version 1.0.2
#r "nuget: Twinify, 1.0.2"
#:package Twinify@1.0.2
#addin nuget:?package=Twinify&version=1.0.2
#tool nuget:?package=Twinify&version=1.0.2
<p align="center"> <img src="https://raw.githubusercontent.com/StevenKamwaza/Twinify.Docs/master/logo-full.png" width="96" height="96" alt="Twinify logo" /> </p>
<h1 align="center">Twinify</h1> <p align="center"><b>Object mapping made simple.</b></p>
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
AddressCityautomatically picks upsource.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. |
Learn more
See the project repository for a deeper look at how the mapping engine is put together, and more
examples of the full configuration surface (ReverseMap, IncludeBase, PreserveReferences,
value resolvers, and so on).
| Product | Versions 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 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. |
-
net10.0
- Twinify.Abstractions (>= 1.0.2)
-
net8.0
- Twinify.Abstractions (>= 1.0.2)
-
net9.0
- Twinify.Abstractions (>= 1.0.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Twinify:
| Package | Downloads |
|---|---|
|
Twinify.DependencyInjection
Dependency injection integration for Twinify. Adds AddTwinify(), AddTwinifyProfiles(), ScanForProfiles(), and ValidateMappings() extension methods for IServiceCollection, for ASP.NET Core, Worker Service, and generic host apps. |
GitHub repositories
This package is not used by any popular GitHub repositories.