Generate complete mapper

⭐ Generate complete mapper

MappingGenerator provides code actions for generating complete mapper class with desired mapping methods. There are two code actions for that purpose:

  • Generate mapper for - Available from the context action on type. Automatically use the selected type as a one of mapping sides. The second type should be selected via config window.
  • Generate complete mapper - Available inside the namespace context, no need to have access to any type source code. Both mapping sides should be selected via config window.

Generate Mapper config window allows us to add the following kinds of method to mapper type:

  • Map A to B - pure mapping method that converts type A to type B. Method signature: B Map(A source)
  • Map B to A - pure mapping method that converts type B to type A. Method signature: A Map(B source)
  • Update A with B - mapping method that updates arguments of type A with values from argument of type B. Method signature: void Update(B source, A target)
  • Update B with A - mapping method that updates arguments of type B with values from argument of type A. Method signature: void Update(A source, B target)
  • Project A to B - Linq projection from type A to type B. Method signature: IQueryable<B> ProjectTo(IQueryable<A> source)
  • Project B to A - Linq projection from type B to type A. Method signature: IQueryable<A> ProjectTo(IQueryable<B> source)

Each method can be generated as:

  • Mapper static member
  • Mapper instance member
  • Mapper instance member + declared as a part of mapping interface
  • Extension method for mapped types

Example usage of Generate complete mapper can look as follows: