TrueMapper 1.1.0
dotnet add package TrueMapper --version 1.1.0
NuGet\Install-Package TrueMapper -Version 1.1.0
<PackageReference Include="TrueMapper" Version="1.1.0" />
<PackageVersion Include="TrueMapper" Version="1.1.0" />
<PackageReference Include="TrueMapper" />
paket add TrueMapper --version 1.1.0
#r "nuget: TrueMapper, 1.1.0"
#:package TrueMapper@1.1.0
#addin nuget:?package=TrueMapper&version=1.1.0
#tool nuget:?package=TrueMapper&version=1.1.0
TrueMapper
🚀 TrueMapper - Advanced Object Mapping Library for .NET
TrueMapper is a powerful, feature-rich object-to-object mapping library for .NET that provides intuitive MapTo() extension methods, comprehensive collection support, smart type conversion, conditional mapping, middleware support, circular reference detection, performance metrics, and much more.
✨ Key Features
🎯 Intuitive Extension Methods
- Fluent
MapTo<T>()
API for seamless object mapping - Intelligent type routing:
obj.MapTo<Type>()
vscollection.MapTo<List<Type>>()
- Clear error messages for invalid mapping scenarios
- Zero-configuration setup for most use cases
📋 Comprehensive Collection Support
- Support for all major .NET collection types:
List<T>
,T[]
,HashSet<T>
,Queue<T>
,Stack<T>
,LinkedList<T>
- Observable and concurrent collections:
ObservableCollection<T>
,ConcurrentBag<T>
,ConcurrentQueue<T>
, etc. - Proper null handling in collection mappings
- Strongly-typed collection transformations
🎯 Smart Type Conversion
- Intelligent type conversion with advanced logic
- Handles complex scenarios like enum-to-string, numeric overflow protection
- Custom boolean representations (
yes/no
,on/off
,1/0
) - Safe numeric conversions with overflow detection
🔄 Conditional Mapping
- Apply mapping logic based on runtime conditions
- Support for conditional transformations
- Flexible rule-based mapping scenarios
🛠️ Middleware Pipeline
- Extensible middleware architecture
- Built-in middleware for validation, logging, caching
- Custom transformation pipeline support
- Pre and post-processing capabilities
🔍 Circular Reference Detection
- Automatic detection and handling of circular references
- Configurable depth limits
- Memory-safe deep object traversal
📊 Performance Metrics
- Built-in performance monitoring
- Memory usage tracking
- Detailed mapping statistics
- Garbage collection monitoring
🏗️ Advanced Configuration
- Fluent API for easy setup
- Auto-discovery mapping profiles
- Multiple configuration strategies
- Profile-based configuration management
📦 Installation
# Install via NuGet Package Manager
Install-Package TrueMapper
# Install via .NET CLI
dotnet add package TrueMapper
# Install via PackageReference
<PackageReference Include="TrueMapper" Version="1.0.0" />
🚀 Quick Start
Basic Usage
using TrueMapper.Core.Extensions;
// Simple object mapping with fluent API
var source = new SourceClass { Name = "John", Age = 30 };
var destination = source.MapTo<DestinationClass>();
// Collection mapping to List<T>
var sourceList = new List<SourceClass> { source };
var destinationList = sourceList.MapTo<List<DestinationClass>>();
// Collection mapping to different collection types
var destinationArray = sourceList.MapTo<DestinationClass[]>();
var destinationHashSet = sourceList.MapTo<HashSet<DestinationClass>>();
// Anonymous objects
var anonymousSource = new { Name = "Jane", Age = 25 };
var result = anonymousSource.MapTo<DestinationClass>();
Intelligent Type Routing
TrueMapper automatically routes to the appropriate mapping logic:
// Single object mapping
Person person = new Person { Name = "John" };
PersonDto dto = person.MapTo<PersonDto>(); // Returns PersonDto
// Collection mapping
List<Person> people = GetPeople();
List<PersonDto> dtos = people.MapTo<List<PersonDto>>(); // Returns List<PersonDto>
// Error: Invalid mapping (collection to single object)
var invalid = people.MapTo<PersonDto>(); // Throws clear error message
Advanced Collection Support
var sourceList = GetSourceItems();
// Various collection types supported
var list = sourceList.MapTo<List<DestinationItem>>();
var array = sourceList.MapTo<DestinationItem[]>();
var hashSet = sourceList.MapTo<HashSet<DestinationItem>>();
var queue = sourceList.MapTo<Queue<DestinationItem>>();
var stack = sourceList.MapTo<Stack<DestinationItem>>();
var observableCollection = sourceList.MapTo<ObservableCollection<DestinationItem>>();
Traditional API (still supported)
using TrueMapper.Core.Core;
var mapper = new TrueMapper();
// Standard mapping with both type parameters
var result1 = mapper.Map<SourceClass, DestinationClass>(source);
// Simplified mapping with destination type inference
var result2 = mapper.Map<DestinationClass>(source);
// Collection mapping
var sourceList = new List<object> { source };
var destinationList = mapper.Map<DestinationClass>(sourceList);
Advanced Configuration
using TrueMapper.Core.Core;
var mapper = new TrueMapper();
// Configure with fluent API
mapper.Configure()
.WithCircularReferenceDetection(true)
.WithMetrics(true)
.WithMaxDepth(20)
.WithNullPropagation(false);
// Create custom mapping profiles
mapper.Configure()
.CreateMap<Source, Destination>()
.ForMember(dest => dest.FullName, src => $"{src.FirstName} {src.LastName}")
.When(src => src.IsActive,
(src, dest) => dest.Status = "Active",
(src, dest) => dest.Status = "Inactive")
.Ignore(dest => dest.InternalId)
.Transform(dest => {
dest.ProcessedAt = DateTime.UtcNow;
return dest;
});
var result = mapper.Map<Source, Destination>(source);
🛡️ Advanced Features
Conditional Mapping
mapper.Configure()
.CreateMap<User, UserDto>()
.When(user => user.IsAdmin,
(user, dto) => dto.Permissions = "All",
(user, dto) => dto.Permissions = "Limited");
Middleware Pipeline
// Built-in validation middleware
pipeline.Use(ValidationMiddleware.NullCheck());
pipeline.Use(ValidationMiddleware.Custom(
ctx => ctx.Source != null,
"Source cannot be null"));
// Built-in logging middleware
pipeline.Use(LoggingMiddleware.Create(msg => Console.WriteLine(msg)));
// Built-in caching middleware
pipeline.Use(CachingMiddleware.Create(
ctx => $"{ctx.SourceType.Name}_{ctx.Source.GetHashCode()}",
ttlMinutes: 30));
// Custom transformation middleware
pipeline.Use(TransformationMiddleware.PostTransform(obj => {
if (obj is ITrackable trackable)
trackable.LastModified = DateTime.UtcNow;
return obj;
}));
Profile-Based Configuration
[MappingProfile(Name = "UserProfile", Priority = 1)]
public class UserMappingProfile : MappingProfile
{
protected override void ConfigureMappings()
{
CreateMap<User, UserDto>()
.ForMember(dto => dto.DisplayName, user => user.GetDisplayName())
.Ignore(dto => dto.InternalNotes);
CreateMap<UserDto, User>()
.When(dto => !string.IsNullOrEmpty(dto.Email),
(dto, user) => user.Email = dto.Email.ToLowerInvariant());
}
}
// Auto-discovery
var registry = ProfileDiscovery.CreateAutoDiscoveredRegistry();
var mapper = new TrueMapper(registry.GetMergedConfiguration());
Performance Monitoring
var mapper = new TrueMapper();
// Perform mappings...
mapper.Map<Source, Destination>(source);
// Get performance metrics
var metrics = mapper.GetMetrics();
Console.WriteLine($"Total mappings: {metrics.TotalMappings}");
Console.WriteLine($"Average time: {metrics.AverageMappingTime}ms");
Console.WriteLine($"Peak memory: {metrics.MemoryStats.PeakMemoryUsage} bytes");
Console.WriteLine($"Circular refs detected: {metrics.CircularReferencesDetected}");
🆚 TrueMapper vs AutoMapper
Feature | TrueMapper | AutoMapper |
---|---|---|
API Compatibility | ✅ AutoMapper + TrueMapper syntax | ✅ AutoMapper syntax |
Smart Type Conversion | ✅ Advanced | ⚠️ Basic |
Conditional Mapping | ✅ Built-in | ❌ Manual |
Middleware Support | ✅ Full Pipeline | ❌ No |
Circular Reference Detection | ✅ Automatic | ⚠️ Manual Config |
Performance Metrics | ✅ Built-in | ❌ No |
Memory Monitoring | ✅ Yes | ❌ No |
Fluent Configuration | ✅ Rich API | ✅ Yes |
Profile Auto-Discovery | ✅ Yes | ⚠️ Manual |
Deep Cloning | ✅ Optimized | ❌ No |
Async Support | ✅ Middleware | ⚠️ Limited |
Migration Path | ✅ Drop-in replacement | N/A |
📊 Performance Benchmarks
BenchmarkDotNet=v0.13.0, OS=Windows 10.0.19044
Intel Core i7-9750H CPU 2.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET 8.0.0 (8.0.0.0), X64 RyuJIT
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|---------------- |---------:|--------:|--------:|----------:|----------:|
| TrueMapper | 127.3 ns | 2.1 ns | 1.8 ns | 0.0229 | 144 B |
| AutoMapper | 285.7 ns | 5.2 ns | 4.9 ns | 0.0534 | 336 B |
| ManualMapping | 45.2 ns | 0.8 ns | 0.7 ns | 0.0153 | 96 B |
🏗️ Architecture
TrueMapper is built with a modular architecture:
- Core: Main mapping engine and interfaces
- Configuration: Fluent API and profile management
- Converters: Smart type conversion system
- Middleware: Extensible processing pipeline
- Performance: Metrics and monitoring
- Profiles: Auto-discovery and management
- Extensions: Convenience methods and utilities
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
git clone https://github.com/iuliansilitra/TrueMapper.git
cd TrueMapper
dotnet restore
dotnet build
dotnet test
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
🏆 Why Choose TrueMapper?
- 🎯 Smart by Default: Intelligent type conversion without manual configuration
- 🛡️ Safe and Robust: Built-in circular reference detection and memory management
- 📈 Performance Focused: Optimized algorithms with built-in monitoring
- 🔧 Highly Configurable: Flexible configuration options for any scenario
- 🚀 Modern Architecture: Designed for .NET 8+ with async and middleware support
- 📦 Easy to Use: Intuitive API with extensive documentation and examples
Made by Iulian Silitra
⭐ Star this repo if you find it useful!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 was computed. 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. |
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.1.0 - MAJOR UPDATE:
- NEW: Intuitive MapTo<T>() extension methods for fluent object mapping
- NEW: Comprehensive collection mapping support (List, Array, HashSet, Queue, Stack, etc.)
- NEW: Intelligent type routing: obj.MapTo<Type>() vs collection.MapTo<List<Type>>()
- ENHANCED: Perfect collection handling with proper null propagation
- IMPROVED: Clear error messages for invalid mapping scenarios
v1.0.6:
- VERIFIED: Interface methods included for flexible API
- Map<TDestination>(object source) fully functional
- Map<TDestination>(IEnumerable<object> source) fully functional
- Complete rebuild with clean cache to ensure proper packaging
v1.0.4:
- Fixed interface definition to include new flexible API methods
- Added Map<TDestination>(object source) to interface
- Added Map<TDestination>(IEnumerable<object> source) to interface
- Complete API compatibility for simplified mapping syntax
v1.0.3:
- Added flexible API syntax with destination type inference
- Enhanced mapping capabilities for simplified usage
- Improved collection mapping support
- Updated documentation with new API examples
v1.0.2:
- Added comprehensive README documentation
- Included detailed usage examples and API reference
- Added performance benchmarks and architecture overview
v1.0.1:
- Added official TrueMapper logo
- Enhanced package presentation
v1.0.0:
- Smart type conversion with advanced logic
- Conditional mapping support
- Middleware pipeline for custom transformations
- Circular reference detection and handling
- Performance metrics and monitoring
- Deep object cloning capabilities
- Fluent configuration API
- Auto-discovery mapping profiles
- Collection mapping with type safety
- Extensive validation and error handling