Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit enum value mapping #336

Closed
latonz opened this issue Apr 14, 2023 · 2 comments · Fixed by #468
Closed

Explicit enum value mapping #336

latonz opened this issue Apr 14, 2023 · 2 comments · Fixed by #468
Labels
enhancement New feature or request
Milestone

Comments

@latonz
Copy link
Contributor

latonz commented Apr 14, 2023

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 ...
        };
    }
}
@latonz latonz added documentation Improvements or additions to documentation enhancement New feature or request and removed documentation Improvements or additions to documentation labels Apr 14, 2023
@github-actions
Copy link

🎉 This issue has been resolved in version 2.9.0-next.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@latonz latonz added this to the v2.9.0 milestone Jun 14, 2023
@github-actions
Copy link

github-actions bot commented Aug 7, 2023

🎉 This issue has been resolved in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant