AnyMapper 1.0.33

.NET 5.0 .NET Standard 2.0 .NET Framework 4.6.1
There is a newer version of this package available.
See the version list below for details.
dotnet add package AnyMapper --version 1.0.33
NuGet\Install-Package AnyMapper -Version 1.0.33
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="AnyMapper" Version="1.0.33" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AnyMapper --version 1.0.33
#r "nuget: AnyMapper, 1.0.33"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install AnyMapper as a Cake Addin
#addin nuget:?package=AnyMapper&version=1.0.33

// Install AnyMapper as a Cake Tool
#tool nuget:?package=AnyMapper&version=1.0.33

AnyMapper

nuget nuget Build status Codacy Badge

A CSharp library mapping alternative to AutoMapper with built-in support for Entity Framework 6 and Entity Framework Core. The terse mapper!

Description

AnyMapper was built as a standalone object mapper that runs on either .Net Framework or .Net Core. The API is backwards compatible with AutoMapper so switching between the two is nearly seamless.

Differences from AutoMapper

AnyMapper will automatically map between objects of different types as long as they have the same names and the types are the same or are different but convertable automatically.

Examples

Simple usage:

using AnyMapper;
var destObject = Mapper.Map<SourceObject, DestObject>(sourceObject);

The above example will map the type SourceObject to type DestObject. Any fields and properties with the same name will be mapped, recursively. You can also map the same type to create a new copy of the data:

var sourceObjectCloned = Mapper.Map<SourceObject, SourceObject>(sourceObject);

For all of the examples below we will use the following test classes:

// *** classes used in all the examples ***
public class SourceObject
{
  public string Name { get; set; }
  public int Id { get; set; }
  public DateTime DateCreated { get; set; }
  public ICollection<SimpleObject> Items { get; set; }
}

public class DestObject
{
  public string Name { get; set; }
  public int Id { get; set; }
  public DateTime DateCreated { get; set; }
  public string Description { get; set; }
  public bool IsEnabled { get; set; }
  public ICollection<SimpleObject> Items { get; set; }
}

// our custom mapping profile that indicates how one object maps to another
public class MyMappingProfile : Profile
{
  public MyMappingProfile()
  {
    CreateMap<SourceObject, DestObject>()
      .ForMember(x => x.Id, x => x.Id)
      .ForMember(x => x.Name, x => x.Name)
      .ForMember(x => x.DateCreated, x => x.DateCreated)
    ;
  }
}

Map one object to another:


// configure our mapping profile
var profile = new MyMappingProfile();
Mapper.Configure(config =>
{
  config.AddProfile(profile);
});

// map one object to another
var sourceObject = new SourceObject { Id = 1, Name = "Source object", DateCreated = new DateTime(2018, 1, 1) };
var destObject = Mapper.Map<SourceObject, DestObject>(sourceObject);
// output
// destObject.Id = 1
// destObject.Name = "Source object"
// destObject.DateCreated = "2018-01-01 00:00:00"
// destObject.Description = null
// destObject.IsEnabled = false
// destObject.Items = null

Implicitly map (no specified profile) two different objects with similar properties, only matching property names will get mapped:

var sourceObject = new SourceObject { Id = 1, Name = "Source object", DateCreated = new DateTime(2018, 1, 1) };
var destObject = Mapper.Map<SourceObject, DestObject>(sourceObject);

// output
// destObject.Id = 1
// destObject.Name = "Source object"
// destObject.DateCreated = "2018-01-01 00:00:00"
// destObject.Description = null
// destObject.IsEnabled = false
// destObject.Items = null

Profiles

AnyMapper supports scanning for profiles in the current assembly using the following setup:

Mapper.Initialize();

You can also specify profiles manually if you don't want to scan for them:

var profiles = new List<Profile>();
profiles.Add(new MyProfile());
profiles.Add(new CustomerProfile());
profiles.Add(new TypesProfile());
Mapper.Initialize(profiles);

Some additional options for finding profiles:

// scan specified assemblies
var myAssembly1 = Assembly.Load(...assemblyPath);
var myAssembly2 = Assembly.Load(...assemblyPath);
Mapper.Initialize(myAssembly1, myAssembly2);

// scan all assemblies in the application (performance will suffer in a large application)
Mapper.Initialize(MappingOptions.ScanAllAssemblies);
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.7

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net5.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.0.34 12,799 3/7/2021
1.0.33 262 3/7/2021
1.0.32 257 3/7/2021
1.0.31 260 3/6/2021
1.0.30 274 3/6/2021
1.0.28 514 7/10/2020
1.0.27 447 7/10/2020
1.0.24 416 7/9/2020
1.0.23 4,870 4/22/2020
1.0.20 732 1/15/2020
1.0.19 512 10/25/2019
1.0.18 367 10/20/2019
1.0.9 2,211 5/16/2019
1.0.4 489 5/15/2019
1.0.0 789 12/18/2018