AutoFapper User Manual
Welcome to the official AutoFapper guide. This comprehensive manual will teach you how to achieve explosive results with just a few simple strokes of code.
Getting It Up
AutoFapper is a powerful tool for handling your object-to-object needs. It eliminates the repetitive manual work of mapping, letting you achieve climactic results with our smooth, fluent API.
Insertion Guide
Slide AutoFapper into your project via NuGet Package Manager:
Install-Package AutoFapper
Or slip it in using the .NET CLI:
dotnet add package AutoFapper
First Time Usage
Your first time with AutoFapper should be gentle and easy:
// Set up your preferences
var configuration = new FapperConfiguration(cfg => {
cfg.CreateMap<Source, Destination>();
});
// Get your fapper ready
var fapper = configuration.CreateFapper();
// Execute with a single stroke
var source = new Source { Name = "Test", Value = 42 };
var destination = fapper.Fap<Destination>(source);
Customizing Your Experience
AutoFapper supports various positions and techniques to enhance your mapping pleasure:
Custom Stroke Patterns
cfg.CreateMap<Source, Destination>()
.ForMember(dest => dest.FullName,
opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"));
Selective Stimulation
cfg.CreateMap<Source, Destination>()
.ForMember(dest => dest.SensitiveArea, opt => opt.Ignore());
Advanced Techniques
Deep Penetration Mapping
AutoFapper goes deep, handling nested objects with ease:
cfg.CreateMap<Order, OrderDto>();
cfg.CreateMap<Customer, CustomerDto>();
// AutoFapper will automatically map nested Customer objects
Group Sessions
Handle multiple objects at once for maximum efficiency:
var sources = new List<Source> { /* ... */ };
var destinations = fapper.Fap<List<Destination>>(sources);
Conditional Climax
cfg.CreateMap<Source, Destination>()
.ForMember(dest => dest.Mature,
opt => opt.MapFrom(src => src.Age >= 18));
API Positions
IFapper Interface
The main tool for getting the job done:
TDestination Fap<TDestination>(object source)
- Quick release to the specified typeTDestination Fap<TSource, TDestination>(TSource source)
- Type-safe satisfactionvoid Fap<TSource, TDestination>(TSource source, TDestination destination)
- Finish on an existing object
Foreplay Methods
CreateMap<TSource, TDestination>()
- Establishes the connectionForMember()
- Focuses on specific areasReverseMap()
- Enables switching positions
Real-World Action
Quick and Dirty DTO Action
public class UserDto
{
public string Username { get; set; }
public string Email { get; set; }
}
public class User
{
public int Id { get; set; }
public string Username { get; set; }
public string Email { get; set; }
public DateTime CreatedAt { get; set; }
}
// Configuration
cfg.CreateMap<UserDto, User>()
.ForMember(dest => dest.CreatedAt,
opt => opt.MapFrom(src => DateTime.Now));
Flattening the Curves
cfg.CreateMap<Customer, CustomerViewModel>()
.ForMember(dest => dest.AddressLine1,
opt => opt.MapFrom(src => src.Address.Line1))
.ForMember(dest => dest.AddressCity,
opt => opt.MapFrom(src => src.Address.City));
When Things Go Soft
Performance Problems
Can't get it up (Missing type map configuration)
Make sure you've established the connection first:
cfg.CreateMap<Source, Destination>();
Premature termination (Null reference exceptions)
Always use protection in your custom resolvers:
cfg.CreateMap<Source, Destination>()
.ForMember(dest => dest.Name,
opt => opt.MapFrom(src => src.Name ?? "Unknown"));
Not lasting long enough (Performance issues)
For marathon sessions, pre-compile your mappings:
var fapper = configuration.CreateFapper();
fapper.WarmUp();
Still Need Help?
If you're still having trouble reaching completion, visit our community support groups or submit your problem to our satisfaction specialists on GitHub.