⚠ Deprecated: Legacy, CriticalBugs
A reflection-free, source-generated object mapper with support for nested objects, collections, and custom mappings.
$ dotnet add package MappingKitA reflection-free, source-generated object mapper for .NET 8+ with zero runtime overhead.
✅ Zero Reflection at Runtime - All mapping code is generated at compile-time
✅ Nested Object Mapping - Automatically maps nested objects and complex hierarchies
✅ Collection Mapping - Built-in support for List<T>, IEnumerable<T>, and arrays
✅ Attribute-Based Mapping - Use [MapFrom("PropertyName")] for property name differences
✅ Fluent API - Configure complex mappings with MapperContext
✅ IDE Friendly - Full IntelliSense support with generated code visible in IDE
dotnet add package MappingKit
using MappingKit.Generated;
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
public class PersonDto
{
public string Name { get; set; }
public int Age { get; set; }
}
// Usage
var person = new Person { Name = "Alice", Age = 30 };
var dto = person.MapTo<Person, PersonDto>();
using MappingKit.Generated;
using MappingKit.Attributes;
public class User
{
public string UserName { get; set; }
public int UserAge { get; set; }
}
public class UserDto
{
[MapFrom("UserName")]
public string Name { get; set; }
[MapFrom("UserAge")]
public int Age { get; set; }
}
// Usage
var user = new User { UserName = "Bob", UserAge = 25 };
var dto = user.MapTo<User, UserDto>();
public class Order
{
public string OrderId { get; set; }
public Customer Customer { get; set; }
public List<OrderItem> Items { get; set; }
}
public class OrderDto
{
public string OrderId { get; set; }
public CustomerDto Customer { get; set; }
public List<OrderItemDto> Items { get; set; }
}
// Automatically maps nested objects and collections
var order = new Order { /* ... */ };
var orderDto = order.MapTo<Order, OrderDto>();var users = new List<User>
{
new User { UserName = "Alice", UserAge = 30 },
new User { UserName = "Bob", UserAge = 25 }
};
var userDtos = users.ToUserDtoList<User, UserDto>();using MappingKit.Attributes;
using MappingKit.Abstractions;
[MapperContext]
public partial class AppMapperContext : IMappingConfigurator
{
public void Configure(IMappingBuilder builder)
{
builder.CreateMap<User, UserDto>()
.ForMember<User, UserDto>(dest => dest.Name, src => src.UserName);
}
}MappingKit uses C# Source Generators to create mapping code at compile-time. This means:
MappingKit maps properties using these rules (in order of priority):
[MapFrom] Attribute - Explicitly specified source propertyAutomatically maps nested objects recursively:
public class Company
{
public string Name { get; set; }
public Address Address { get; set; }
public List<Employee> Employees { get; set; }
}
// All nested objects (Address, Employees) are automatically mapped
var dto = company.MapTo<Company, CompanyDto>();Supports various collection types:
List<T>IEnumerable<T>ICollection<T>T[] (arrays)MappingKit handles null values gracefully:
Add to your .csproj:
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>For consuming projects, reference both MappingKit and the Generator:
<ItemGroup>
<ProjectReference Include="path\to\MappingKit.csproj" />
<ProjectReference Include="path\to\MappingKit.Generator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>This is an IDE caching issue. The code compiles and runs fine. To fix:
dotnet build-server shutdown && dotnet buildMappingKit generates code at compile-time, so there's zero runtime overhead. The generated mapping code is as fast as hand-written code.
TDest MapTo<TSrc, TDest>(this TSrc source) - Map single objectList<TDest> ToUserDtoList<TSrc, TDest>(this IEnumerable<TSrc> sources) - Map collection[MapFrom("SourcePropertyName")] - Specify source property for mapping[MapperContext] - Mark class as mapper configuration contextIMappingBuilder - Fluent mapping configurationIMappingConfigurator - Mapper context configurationMIT License - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.