Skip to content

Explicit enum value mapping #336

Description

@latonz

Add the possibility to explicitly map one enum value to another enum value.

enum CarBrand { Audi, Stellantis }
enum CarBrandDto { Audi, FiatChrysler }

// declaration
[Mapper]
public partial DtoMapper
{
    [MapEnum(EnumMappingStrategy.ByName]
    [MapEnumValue(CarBrand.Stellantis, CarBrandDto.FiatChrysler)]
    public partial CarBrandDto ToDto(CarBrand brand); 
}

// implementation
public partial DtoMapper
{
    public partial CarBrandDto ToDto(CarBrand brand)
    {
        return source switch
        {
            CarBrand.Audi => CarBrandDto.Audi,
            CarBrand.Stellantis => CarBrandDto.FiatChrysler,
            _ => throw new ...
        };
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions