DeepMapper 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package DeepMapper --version 1.0.6
NuGet\Install-Package DeepMapper -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="DeepMapper" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DeepMapper --version 1.0.6
#r "nuget: DeepMapper, 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.
// Install DeepMapper as a Cake Addin
#addin nuget:?package=DeepMapper&version=1.0.6

// Install DeepMapper as a Cake Tool
#tool nuget:?package=DeepMapper&version=1.0.6

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 registeration.

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 namespcace 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 beeing mapped to null

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. 
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 83 5/8/2024
1.0.6 165 4/12/2023
1.0.5 259 3/8/2023
1.0.4 269 12/5/2022
1.0.3 315 11/17/2022
1.0.2 338 11/5/2022
1.0.1 363 10/23/2022
1.0.0 374 10/21/2022