TrueMapper 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package TrueMapper --version 1.0.6
                    
NuGet\Install-Package TrueMapper -Version 1.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TrueMapper" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TrueMapper" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="TrueMapper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TrueMapper --version 1.0.6
                    
#r "nuget: TrueMapper, 1.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TrueMapper@1.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TrueMapper&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=TrueMapper&version=1.0.6
                    
Install as a Cake Tool

TrueMapper

🚀 TrueMapper - Advanced Object Mapping Library for .NET

TrueMapper is a powerful, feature-rich object-to-object mapping library for .NET that goes beyond traditional mapping sol## 🛡️ Advanced Featuress smart type conversion, conditional mapping, middleware support, circular reference detection, performance metrics, and much more.

✨ Key Features

🎯 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.Core;
using TrueMapper.Core.Extensions;

// Simple object mapping
var source = new SourceClass { Name = "John", Age = 30 };
var destination = source.MapTo<DestinationClass>();

// Collection mapping
var sourceList = new List<SourceClass> { source };
var destinationList = sourceList.MapTo<DestinationClass>();

// Deep cloning
var cloned = source.DeepClone();

Alternative API Syntax

TrueMapper supports flexible API usage patterns:

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.

🏆 Why Choose TrueMapper?

  1. 🎯 Smart by Default: Intelligent type conversion without manual configuration
  2. 🛡️ Safe and Robust: Built-in circular reference detection and memory management
  3. 📈 Performance Focused: Optimized algorithms with built-in monitoring
  4. 🔧 Highly Configurable: Flexible configuration options for any scenario
  5. 🚀 Modern Architecture: Designed for .NET 8+ with async and middleware support
  6. 📦 Easy to Use: Intuitive API with extensive documentation and examples

Made by Iulian Silitra

Star this repo if you find it useful!

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
1.1.0 247 9/15/2025
1.0.6 211 9/14/2025
1.0.5 203 9/14/2025
1.0.4 198 9/14/2025
1.0.3 205 9/14/2025
1.0.2 206 9/14/2025
1.0.1 203 9/14/2025
1.0.0 205 9/14/2025

v1.0.5:
     - 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