DeepMapper 1.0.7

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

Deep Mapper

It is an object mapper with zero configuration. It maps using two methods conventional mapping and configurational mapping. It also maps nested classes recursivley to a new instance. This library can be used for deep copying as well.

Add DI to the project.

services.AddDeepMapping(config => 
{ 
     config.UseConventionalMapping();
});

Conventional Mapping

This method requires no configurations and uses property names to map objects and set the unmatched properties to default. Use IConventionalMapper interface or IDeepMapper. This class can be used without DI just by instantiating a new instance of ConventionalMapper class.

var obj = mapper.Map<TDestination>(TSource);

//or 

var obj = new ConventionalMapper().Map<TDestination>(TSource);

//or 

var destintion = new ConventionalMapper().Map(Type destinationType, object? sourceObject)

Conventioal mapping can use constructors to fill destination class.

class TDestination 
{
  public TProperty Property {get; private set;}
}

// Or

class TDestination 
{
  TDestination(TProperty property)
  {
     Property = property
  }
  public TProperty Property {get;}
}
 

Conventional mapper is able to map structs to classes (and vice versa) to fill properties with the same name. The convention is case insensitive.

Configurational Mapping

In this method the library uses configuration for a types in the service registration.

config.Map<TSource, TDestination>()
              .ToProperty(destination => TProperty, source => TProperty)
              .ToConstant(destination => TProperty, object)
              .ToDefault(destination => TProperty)
              .Ignore(destination => TProperty);

The UseConventionalMapping() in the configuration enables the configurational mapper to map the rest of the properties using name conventions.

// Use IDeepMapper for configurational mapping
var obj = mapper.Map<TDestination>(TSource);

Version 1.0.3

  • MapAsync has been added to IDeepMapper for async mapping.
  • Map functions has been added to IEnumerable interface for mapping collection in DeepMapper.Extensions namespace. This must be used when DI activated.
  • The DI extension moved to new namespace DeepMapper.Extensions alongside Map for IEnumerable.
// Map for IEnumerable
IEnumerable<TDestination> objects = IEnumerable.Map<TDestination>();

Version 1.0.5

  • MapDictionary has been added to Conventional mapper.
var keyValue = new Dictionary<string, object?>();
keyValue["P1"] = "ONE";
keyValue["P2"] = "TWO";
keyValue["P3"] = new object();

var newObj = new ConventionalMapper().Map<T>(keyValue);

Version 1.0.6

  • Fixes bug in nested objects being mapped to null.

Version 1.0.7

  • Adds array mapping to type T[]. The array can be in an object as a property or as root. The mapping between IList is not supported and the property must be of type T[].

T[] newObj = new ConventionalMapper().Map<T[]>(sourceObj);

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.

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.0.7 142 5/8/2024
1.0.6 225 4/12/2023
1.0.5 370 3/8/2023 1.0.5 is deprecated because it has critical bugs.
1.0.4 331 12/5/2022
1.0.3 376 11/17/2022
1.0.2 401 11/5/2022
1.0.1 455 10/23/2022
1.0.0 439 10/21/2022