Branch | Status |
---|---|
Master | |
Develop |
"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.
The reasons behind why I don't use AutoMapper
If you find this extension useful (you feel it helps you on the daily basis) you can support further development by buying me a coffee (it's simple, just click the button below). Sometimes it's hard to stay awake till midnight implementing new features, coffee helps me with that. I'm really appreciate for your support.
Before you start any contributing work, please read the contribution guidline
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
Non-void method that takes single parameter
public UserDTO Map(UserEntity entity)
{
}
Void method that takes two parameters
public void Update(UserDTO source, UserEntity target)
{
}
Constructor method that takes single complex parameter
public UserDTO(UserEntity user)
{
}
Constructor method that takes more than one parameter
public UserDTO(string firstName, string lastName, int age, int cash)
{
}
Void member method that takes single parameter
public void UpdateWith(UserEntity en)
{
}
Void member method with more than one parameter
public void Update(string firstName, string lastName, int age)
{
}
CS0029 Cannot implicitly convert type 'type' to 'type'
CS0266 Cannot implicitly convert type 'type1' to 'type2'. An explicit conversion exists (are you missing a cast?)
CS7036 There is no argument given that corresponds to the required formal parameter
-
Complete empty initialization block in lambda expression
Expression<Func<T,T2>> = (T) => new T2{}
-
Provide local accessible variables as parameters for method and constructor invocation
-
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);