Skip to content

Ignore enum values #337

Description

@latonz

Add the option to ignore source / target enum values from enum mappings.
This is especially useful in context of #325 (to ignore an expected unmapped enum member).

enum Fruit { Apple, Kiwi }
enum FruitDto { Apple, Banana }

// declaration
[Mapper]
public partial DtoMapper
{
    [MapEnum(EnumMappingStrategy.ByName)]
    [MapperIgnoreSource(Fruit.Kiwi)]
    [MapperIgnoreTarget(FruitDto.Banana)]
    public partial FruitDto ToDto(Fruit source); 
}

// implementation
public partial DtoMapper
{
    public partial FruitDto ToDto(Fruit source)
    {
        return source switch
        {
            Fruit.Apple => FruitDto.Apple,
            _ => throw new ...
        };
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions