Enum mappings
An enum mapping can be customized by setting the strategy to use.
Apply the MapEnumAttribute
and pass the strategy to be used for this enum.
It is also possible to set the strategy for the entire mapper via the MapperAttribute
.
Available strategies:
Name | Description |
---|---|
ByValue | Matches enum entries by their values (default) |
ByName | Matches enum entries by their exact names |
The IgnoreCase
property allows to opt in for case insensitive mappings (defaults to false
).
- Global (Mapper Level)
- Enum (Mapping Method Level)
Applied to all enums mapped inside this mapper.
[Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName, EnumMappingIgnoreCase = true)]
public partial class CarMapper
{
...
}
Applied to the specific enum mapped by this method. Attribute is only valid on mapping method with enums as parameters.
[Mapper]
public partial class CarMapper
{
[MapEnum(EnumMappingStrategy.ByName, IgnoreCase = true)]
public partial CarMakeDto MapMake(CarMake make);
}