Mapping methods

One of the main features of MappingGenerator is generating implementation for mapping methods. Every method, which signature meets the criteria described in the paragraphs below, can be implemented by MappingGenerator. Both types of methods - synchronous and asynchronous - are supported. To generate the implementation:

  1. Put the cursor on the method signature
  2. Open the action menu (ctr + . or alt + enter for Resharper users)
  3. Select 🔥 Generate mapping code from the action menu

Synchronous mappings

Pure mapping method

A non-void method that takes a single parameter

public UserDTO Map(UserEntity entity)
{
    throw new NotImplementedException();
}

Example:

Update second parameter method

A void method that takes two complex parameters

public void Update(UserDTO source, UserEntity target)
{
    throw new NotImplementedException();
}

Example:

Updating this object’s methods

Void member method that takes a single complex parameter

public void UpdateWith(UserEntity en)
{
    throw new NotImplementedException();
}

Example:

Void member method with more than one parameter

public void UpdateWith(string firstName, string lastName, int age)
{
    throw new NotImplementedException();
}

Example:

Mapping Constructor

Constructor method that takes a single complex parameter

public UserDTO(UserEntity user)
{
    throw new NotImplementedException();
}

Example:

Constructor method that takes more than one parameter

public UserDTO(string firstName, string lastName, int age)
{
    throw new NotImplementedException();
}

Example:

Method converting this object to another

A non-void method that accepts no parameters.

public UserEntity ToEntity()
{
    throw new NotImplementedException();
}

Example:

Asynchronous mappings

MappingGenerator supports asynchronous counterparts of all method types mentioned in Synchronous mappings section (when applicable). Every asynchronous method can optionally accept CancellationToken parameter. Both Task and ValueTask return types are supported.

public Task<UserDTO> Map(UserEntity entity, CancellationToken token)
{
    throw new NotImplementedException();
}