ValueMapper 1.2.4

dotnet add package ValueMapper --version 1.2.4
                    
NuGet\Install-Package ValueMapper -Version 1.2.4
                    
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="ValueMapper" Version="1.2.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ValueMapper" Version="1.2.4" />
                    
Directory.Packages.props
<PackageReference Include="ValueMapper" />
                    
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 ValueMapper --version 1.2.4
                    
#r "nuget: ValueMapper, 1.2.4"
                    
#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 ValueMapper@1.2.4
                    
#: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=ValueMapper&version=1.2.4
                    
Install as a Cake Addin
#tool nuget:?package=ValueMapper&version=1.2.4
                    
Install as a Cake Tool

ValueMapper

A high-performance, lightweight object-to-object mapper for .NET with zero dependencies. ValueMapper provides fast mapping capabilities with a simple API, making it easy to map between different object types while maintaining good performance.

Feature Comparison

Feature ValueMapper Mapster AutoMapper
Zero Dependencies
Basic Property Mapping
Flattening
Deep Object Mapping
Collection Mapping
Enum Mapping
Custom Property Mapping ✅ (attr)
Property Ignoring
Type Conversion
Nullable Handling
Configuration API
Custom Value Resolvers
Conditional Mapping
Circular Reference Handling
Before/After Mapping Actions
Runtime Configuration
Mapping Validation
Collection Type Conversion ❌ (List→List only)
Parallel Collection Mapping ✅ (built-in) ❌+ ❌+
Compile-time Type Safety ❌‡ ❌‡
Mapping Cache
Performance (vs Manual)* ~11.95x slower ~8.11x slower ~12.67x slower

* Based on benchmark results for single object mapping. For collection mapping (100,000 items), ValueMapper performs better: ValueMapper (39.84ms), Mapster (65.34ms), AutoMapper (70.80ms).

  • Can be implemented manually

Features

  • ✨ Zero dependencies
  • 🚀 High performance
  • 💡 Simple API
  • 🔄 Automatic type conversion
  • 🏷️ Custom property mapping via attributes
  • ⏭️ Property ignoring
  • 📝 Collection mapping
  • 🔄 Enum mapping (case-insensitive)
  • 🧵 Parallel collection mapping for large datasets
  • 🔒 Thread-safe operation
  • 🔥 Mapping compilation caching

Installation

dotnet add package ValueMapper

Usage Examples

Basic Property Mapping

var source = new Source
{
    Name = "John Doe",
    Age = 30,
    City = "New York"
};

var destination = ValueMapper.Map<Source, Destination>(source);

Custom Property Mapping Using Attributes

public class Source
{
    [ValueMapperMapping("CustomName")]
    public string SourceProperty { get; set; }
}

public class Destination
{
    public string CustomName { get; set; }
}

var source = new Source { SourceProperty = "Custom Value" };
var destination = ValueMapper.Map<Source, Destination>(source);
// destination.CustomName will contain "Custom Value"

Ignoring Properties

public class Source
{
    public string Name { get; set; }
    [ValueMapperIgnore]
    public string IgnoredProperty { get; set; }
}

// Or ignore properties at runtime
var ignoredProperties = new HashSet<string> { "Age" };
var destination = ValueMapper.Map<Source, Destination>(source, ignoredProperties);

Collection Mapping

var sourceList = new List<Source>
{
    new Source { Name = "John", Age = 30 },
    new Source { Name = "Jane", Age = 25 }
};

var destinationList = ValueMapper.MapList<Source, Destination>(sourceList);

Enum Mapping (Case-Insensitive)

public enum SampleEnum
{
    None,
    Value1,
    Value2
}

public class Source
{
    public string EnumValue { get; set; }  // Can be "Value1" or "value1"
}

public class Destination
{
    public SampleEnum EnumValue { get; set; }
}

Type Conversion Support

public class Source
{
    public int IntValue { get; set; }
    public double DoubleValue { get; set; }
    public string StringNumber { get; set; }
}

public class Destination
{
    public long LongValue { get; set; }      // Converts from int
    public float FloatValue { get; set; }    // Converts from double
    public int IntFromString { get; set; }   // Converts from string
}

Nullable Handling

public class Source
{
    public string Value { get; set; }  // Can be null
}

public class Destination
{
    public int? NullableValue { get; set; }  // Will be null if source is null
}

Performance

ValueMapper is designed for high performance. Here are some benchmark results comparing it with other popular mappers:

Performance Comparison

Single Object Mapping (Relative to Manual Implementation)
Mapper Performance Relative Slowdown
Manual (baseline) 0.000ms 1x
ValueMapper 0.001ms 11.95x slower
AutoMapper 0.002ms 12.67x slower
Mapster 0.001ms 8.11x slower
ManuallyImplemented 0.001ms 7.29x slower
Collection Mapping (100,000 items)
Mapper Time per Operation
ValueMapperCollection 39.840ms
AutoMapperCollection 70.800ms
MapsterCollection 65.340ms
ManuallyImplementedCollection 45.310ms
Warmup Performance (First-time Use)
Mapper Warmup Time
ValueMapper 0ms
AutoMapper 7ms
Mapster 10ms
ManuallyImplemented No warmup needed

Key Performance Insights:

  1. Single Object Mapping:

    • All mappers show minimal overhead for single object mapping
    • Mapster shows the best performance among the automated mappers
    • ValueMapper performs similarly to other popular mappers
  2. Collection Mapping:

    • ValueMapper shows strong performance with large collections
    • ~43% faster than Mapster
    • ~77% faster than AutoMapper
    • Close to manually implemented mapping performance
  3. Warmup Time:

    • ValueMapper has excellent cold start performance
    • No significant warmup overhead
    • Better startup time compared to both Mapster and AutoMapper

Run the benchmarks yourself:

cd ValueMapper/Benchmark
dotnet run         # Full benchmarks
dotnet run quick   # Quick benchmarks

Cache Management

// Clear all caches
ValueMapper.ClearCaches();

// Pre-warm mapping for specific types
ValueMapper.PreWarmMapping<Source, Destination>();

// Clear cache for specific types
ValueMapper.Clear<Source, Destination>();

Known Limitations

  1. Deep object mapping is not currently supported

    • The Map_DeepObjectMapping_ShouldMapCorrectly test demonstrates this limitation
    • Complex nested objects with multiple levels are not automatically mapped
  2. No circular reference detection

  3. No support for mapping private properties

  4. Collection type conversion (e.g., List<T> to Array<T>) is not supported

  5. No support for custom value converters

  6. No support for conditional mapping

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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 was computed.  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 was computed.  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 was computed.  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.

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.2.4 133 6/14/2025
1.2.3 124 6/14/2025
1.2.2 132 6/14/2025
1.2.0 132 6/14/2025
1.0.0 137 6/14/2025