Popularity
6.1
Stable
Activity
6.5
Declining
920
30
72

Description

"AutoMapper" like, Roslyn based, code fix provider that allows generating mapping code in design time. The main features are: generating the implementation of mapping methods and constructors, clone methods and lambda projections. There are also a few additional features like splatting or completing method invocation and object initialization with local variables. You can download it as Visual Studio Extension from Visual Studio Marketplace.

Programming language: C#
License: MIT License
Latest version: v1.20.463

Mapping Generator alternatives and similar packages

Based on the "Object to object mapping" category.
Alternatively, view Mapping Generator alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Mapping Generator or a related project?

Add another 'Object to object mapping' Package

README

WHY THIS PROJECT IS ARCHIVED - EXPLANATION


MappingGenerator is discontinued in the form of FOSS. I spent the last three months (March 2021 - June 2021) working hard on improving MappingGenerator. I solved many issues and added a bunch of new cool features. I also made a general refactoring which restored the project maintainability. All of that cost me a lot of my private time and I did it all by myself, so I decided to convert MappingGenerator into a commercial product. A perpetual license for a new version of MappingGenerator can be obtained via the official product website https://www.mappinggenerator.net/

I would like to thank all of you who contributed to this product by reporting issues, testing, authoring PRs, or buying me coffee. PR authors (except the Only README Updaters) and Coffee Buyers will be awarded with a special license for MappingGenerator for free - I will send them an email with details in a few days.

Links:


Mapping Generator Tweet

"AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time. Read more Mapping Generator – Design Time Alternative to AutoMapper

You can download it as Visual Studio Extension from Visual Studio Marketplace.

Motivation

The reasons behind why I don't use AutoMapper

Contributing

Before you start any contributing work, please read the contribution guideline

Supported IDE

VisualStudio.

Install as VSIX from Market place or as a NuGet package. Verify your Roslyn integration option in case you are using R#.

JetBrains Rider

Install as a NuGet package

VSCode

Install as a NuGet package or use this instruction to install from VSIX

Using along with Resharper

If you are not able to open Roslyn refactoring menu (ctr + .) please verify your Resharper settings related to Visual Studio Integration or Visual Studio code analysis (depends on the R# version). For more information please check #50

[resharper settings](doc/resharper_settings.jpg)

Main features

Generate mapping method body

Pure mapping method

Non-void method that takes single parameter

public UserDTO Map(UserEntity entity)
{

}

[Generating pure mapping method implementation](doc/pure_mapping_method_newone.gif)

Updating method

Void method that takes two parameters

public void Update(UserDTO source, UserEntity target)
{

}

[Generating update method implementation](doc/update_method.gif)

Mapping Constructor

Constructor method that takes single complex parameter

public UserDTO(UserEntity user)
{

}

[Generating mapping constructor implementation](doc/mapping_constructor.gif)

Constructor method that takes more than one parameter

public UserDTO(string firstName, string lastName, int age, int cash)
{
}

Generating multi-parameter constructor

Updating member method

Void member method that takes single parameter

public void UpdateWith(UserEntity en)
{

}

[Generating update member method imeplementation](doc/update_member_method.gif)

Void member method with more than one parameter

public void Update(string firstName, string lastName, int age)
{
}

Generate inline code for fixing Compiler Errors:

CS0029 Cannot implicitly convert type 'type' to 'type'

cs0029

CS0266 Cannot implicitly convert type 'type1' to 'type2'. An explicit conversion exists (are you missing a cast?)

cs0266

CS7036 There is no argument given that corresponds to the required formal parameter

CS7036

Other mappings

  • Complete empty initialization block [Generate initialization bloc](doc/emptyInitialization.gif)

  • Complete empty initialization block in lambda expression Expression<Func<T,T2>> = (T) => new T2{} initialization block in lambda expression

  • Provide local accessible variables as parameters for method and constructor invocation [locals as parameters](doc/localsforconstructor.gif)

  • Create missing mapping lambda
    [mapping lambda](doc/mapping_lambda.gif)

  • Generate ICloneable interface implementation generate clone method

Object scaffolding

sample scaffolding

Mapping rules

  • Mapping Property-To-Property csharp target.FirstName = source.FirstName; target.LastName = source.LastName;
  • Mapping Method Call-To-Property csharp target.Total = source.GetTotal()
  • Flattening with sub-property csharp target.UnitId = source.Unit.Id
  • Mapping complex property csharp target.MainAddress = new AddressDTO(){ BuildingNo = source.MainAddress.BuildingNo, City = source.MainAddress.City, FlatNo = source.MainAddress.FlatNo, Street = source.MainAddress.Street, ZipCode = source.MainAddress.ZipCode };
  • Mapping collections csharp target.Addresses = source.Addresses.Select(sourceAddresse => new AddressDTO(){ BuildingNo = sourceAddresse.BuildingNo, City = sourceAddresse.City, FlatNo = sourceAddresse.FlatNo, Street = sourceAddresse.Street, ZipCode = sourceAddresse.ZipCode }).ToList().AsReadOnly();
  • Unwrapping wrappers csharp customerEntity.Kind = cutomerDTO.Kind.Selected;
    public enum CustomerKind
    {
        Regular,
        Premium
    }

    public class Dropdown<T>
    {
        public List<T> AllOptions { get; set; }

        public T Selected { get; set; }
    }

    public class CustomerDTO
    {
        public string Name { get; set; }
        public Dropdown<CustomerKind> Kind { get; set; }
    }

    public class UserEntity
    {
        public string Name { get; set; }
        public CustomerKind Kind { get; set; }
    }
  • Using existing direct mapping constructor

    target.MainAddress = new AddressDTO(source.MainAddress);
    
  • using existing multi-parameter constuctor

    this.User =  new UserDTO(firstName: entity.FirstName, lastName: entity.LastName, age: entity.Age);
    


*Note that all licence references and agreements mentioned in the Mapping Generator README section above are relevant to that project's source code only.