- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Home
SourceMapper is code generator for mappings defined with using of attributes used in interfaces or abstract classes.
It is based on C# 9 feature called Source Generators. During build process it generates mapping classes and methods that can be used in your project.
Install using nuget package manager:
Install-Package Compentio.SourceMapperor .NET CLI:
dotnet add package Compentio.SourceMapperTo define mapping we have to mark mapping abstract class or interface with MapperAttribute:
[Mapper]
public interface INotesMapper
{
    NoteDto MapToDto(NoteDao source);
}This will generate mapping class with default class name NotesMapper for properties that names are the same for NoteDto and NoteDao classes.
The generated class is in the same namespace as its base abstract class of interface. It can be found in project in Visual Studio:
Dependencies -> Analyzers -> Compentio.SourceMapper.Generators.MainSourceGenerator.
When the names are different than we can use Source and Target names of the properties:
[Mapper(ClassName = "InterfaceUserMapper")]
public interface IUserMapper
{
    [Mapping(Source = nameof(UserDao.FirstName), Target = nameof(UserInfo.Name))]
    UserInfo MapToDomainMoodel(UserDao userDao);       
}The ClassName property in MapperAttribute is responsible for name of the generated mapping class.
For default MapperAttribute interface prefix I is removed or Impl suffix added to the generated class name if there is no I prefix
in the mapping interface name.
@alekshura SourceMapper 2021