• This repository has been archived on 16/Jan/2022
  • Stars
    star
    1,031
  • Rank 44,693 (Top 0.9 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 7 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ”„ "AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time.

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.

πŸ”₯ Important 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

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

Updating method

Void method that takes two parameters

public void Update(UserDTO source, UserEntity target)
{
    
}

Generating update method implementation

Mapping Constructor

Constructor method that takes single complex parameter

public UserDTO(UserEntity user)
{
    
}

Generating mapping constructor implementation

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

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

  • 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

  • Create missing mapping lambda
    mapping lambda

  • Generate ICloneable interface implementation generate clone method

Object scaffolding

sample scaffolding

Mapping rules

  • Mapping Property-To-Property

    target.FirstName = source.FirstName;
    target.LastName = source.LastName;
  • Mapping Method Call-To-Property

    target.Total = source.GetTotal()
  • Flattening with sub-property

    target.UnitId = source.Unit.Id
  • Mapping complex property

     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

    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

    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);

More Repositories

1

polish-it-conferences

List of Polish IT Conferences
124
star
2

CSharpExtensions

A set of annotations and analyzers that add additional constraints to your codebase
C#
122
star
3

NScenario

Dead simple library for annotating steps of test case scenarios.
HTML
67
star
4

CsharpMacros

A simple template base system of macros for C# that can be executed in design time
C#
63
star
5

SmartCodeGenerator

C#
38
star
6

Tellurium

A utility pack to create maintainable and reliable UI tests using Selenium with additional support for ASP.NET MVC projects.
C#
34
star
7

msbuild-cheatsheet

34
star
8

DDDToolbox

A set of Roslyn refactorings supporting DDD design
C#
34
star
9

GRPC-Mock-Server

Super fast, platform independent, standalone component for mocking GRPC services using WireMock.NET stubbing engine
C#
32
star
10

MultithreadingAnalyzer

A set of Roslyn analyzers related to multithreading
C#
30
star
11

MappingGeneratorReleases

24
star
12

RoslynTestKit

A lightweight framework for writing unit tests for Roslyn diagnostic analyzers, code fixes, refactorings and completion providers.
C#
24
star
13

DependencyGraph

A small F# application to visualize .net assembly dependencies
F#
21
star
14

VanillaTransformer

A simple generic text file transformer
C#
20
star
15

ExceptionAnalyzer

A set of Roslyn analyzers related to exceptions usages
C#
20
star
16

ArchitecturalPatterns

Link aggregator of architectural patterns implementation
19
star
17

TCMetaRunnersPowerPack

A set of Team City meta runners
13
star
18

VsixPublisherAction

GithubAction for publishing extensions to Visual Studio Marketplace
TypeScript
11
star
19

ScriptRunnerPOC

C#
9
star
20

ProjectGraphs

PowerShell script to draw graph of c# projects dependencies
PowerShell
9
star
21

MyToolbox

7
star
22

CQRSsnippets

Resharper Live Templates for CQRS described in https://cezarypiatek.github.io/post/cqrs-snippets/
6
star
23

SampleWebApiTestsWithApprovals

C#
5
star
24

ApprovalTestsExtensions

A set of helper classes that facilitate the usage of ApprovalTests.NET library
C#
5
star
25

PluginArchitectureDemo

C#
3
star
26

Presentations

3
star
27

DebuggingDemo

C#
3
star
28

DotnetCodeAnalysisEssentialSetup

A quick guideline how to setup static code analysis for dotnet project with a list of essential analyzer packages.
3
star
29

SampleWebApiClientGeneration

C#
3
star
30

PSHistory

PowerShell lookup for recent locations and commands
PowerShell
3
star
31

NextVersionGeneratorAction

GithubAction for generating next version number based on the git log and message patterns
TypeScript
2
star
32

VsixVersionAction

GithubAction for setting Version of Visual Studio Extensions
JavaScript
2
star
33

MappingGeneratorIssueTracker

This is a issue tracker for MappingGenerator
C#
2
star
34

cezarypiatek.github.io

Personal blog https://cezarypiatek.github.io
HTML
2
star
35

SmoothSailing

A library to support Helm Chart installation in Kubernetes cluster from .NET code
C#
1
star
36

SampleRecordAnalyzer

PowerShell
1
star
37

BashVsPowerShell

Cheatsheet with syntax comparison between Bash and Powershell
1
star
38

HackingSculpfunS10

1
star
39

UniversalTemplates

C#
1
star
40

OnBuildGenerator-Example

Example usage of MappingGenerator.OnBuildGenerator
C#
1
star
41

TextExtensions

C#
1
star
42

CodePresenter

A tool to visualise your codebase
PowerShell
1
star
43

Tellurium.StableElements

A set of Selenium extensions that solve StaleElementReferenceException problem
C#
1
star