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

Support partial base classes #38

Closed
latonz opened this issue Mar 1, 2022 · 0 comments · Fixed by #42
Closed

Support partial base classes #38

latonz opened this issue Mar 1, 2022 · 0 comments · Fixed by #42
Labels
enhancement New feature or request

Comments

@latonz
Copy link
Contributor

latonz commented Mar 1, 2022

Mapperly supports base classes with mapping methods which have a body.
E.g.

class DateMapper
{
    protected DateOnly DateTimeToDateOnly(DateTime dt) => DateOnly.FromDateTime(dt);
}

[Mapper]
partial class DtoMapper : DateMapper
{
    public partial CarDto ToDto(Car car);
}

In this sample, when the DtoMapper needs to map a DateTime to a DateOnly Mapperly will use the DateMapper.DateTimeToDateOnly method.

However if the DateMapper is itself a Mapper with partial methods, these won't be re-used. This should be improved.
E.g.

[Mapper]
partial class BaseMapper
{
    protected partial BaseDto ToBaseDto(BaseObject source);
}

[Mapper]
partial class DtoMapper : BaseMapper
{
    public partial CarDto ToDto(Car car);
}

If the DtoMapper needs to map a property of source type BaseObject to target type BaseDto it should re-use the already built mapping BaseMapper.ToBaseDto, but this currently does not work.

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