import CodeBlock from '@theme/CodeBlock'; import CarSource from '!!raw-loader!../../src/data/generated/samples/Car.cs'; import CarDtoSource from '!!raw-loader!../../src/data/generated/samples/CarDto.cs'; import CarMapperSource from '!!raw-loader!../../src/data/generated/samples/CarMapper.cs'; import GeneratedCarMapperSource from '!!raw-loader!../../src/data/generated/samples/CarMapper.g.cs';
This example will show you what kind of code Mapperly generates. It is based on the Mapperly sample. To view the generated code of your own mapper, refer to the generated source configuration.
In this example, we have a car class with some general information.
{CarSource}
Our sample target classes are mostly the same as the source classes. For demonstration purposes, we named the manufacturer property differently to show how Mapperly can handle this use case.
{CarDtoSource}
The actual mapper is pretty simple. We use a static mapper class in this example.
As usual, we need to mark the mapper with the [Mapper]
attribute, so that the source generator is able to recognize it.
Because the manufacturer/producer properties are named differently, we also need to configure that via an attribute.
In addition, because the CarColor
and CarColorDto
entries have different numeric values, we need to configure Mapperly to map them by their name.
{CarMapperSource}
{GeneratedCarMapperSource}