Giter VIP home page Giter VIP logo

mappinggenerator's Introduction

Mapping Generator

Branch Status
Master Build status
Develop Build status

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

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

Contributing

Before you start any contributig work, plase read the contribution guidline

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 parameter

public UserDTO(UserEntity user)
{
    
}

Generating mapping constructor implementation

Updating member method

Void member method that takes single parameter

public void UpdateWith(UserEntity en)
{
    
}

Generating update member method imeplementation

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

Mapping features

  • 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

    var targetMainAddress = new AddressDTO();
    targetMainAddress.BuildingNo = source.MainAddress.BuildingNo;
    targetMainAddress.City = source.MainAddress.City;
    targetMainAddress.FlatNo = source.MainAddress.FlatNo;
    targetMainAddress.Street = source.MainAddress.Street;
    targetMainAddress.ZipCode = source.MainAddress.ZipCode;
    target.MainAddress = targetMainAddress;
  • Mapping collections

    target.Addresses = source.Addresses.Select(addressEntity =>
    {
        var addressDTO = new AddressDTO();
        addressDTO.BuildingNo = addressEntity.BuildingNo;
        addressDTO.City = addressEntity.City;
        addressDTO.FlatNo = addressEntity.FlatNo;
        addressDTO.Street = addressEntity.Street;
        addressDTO.ZipCode = addressEntity.ZipCode;
        return addressDTO;
    }).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);

mappinggenerator's People

Contributors

cezarypiatek avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.