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

Add support for mapping method parameters to the target type properties #1442

Closed
Eirenarch opened this issue Aug 6, 2024 · 2 comments
Closed
Labels
enhancement New feature or request

Comments

@Eirenarch
Copy link

I am porting some manual mapping code to use mapperly as it is the first mapper I actually like. I use immutable positional records as DTOs. A good deal of my DTOs have a CanEdit property (some have more of these). The UI uses these to know if it should display edit button and so on. If the user can edit is determined by complex logic so I compute it in advance and then do the mapping with methods like this

public static DeviceDto ToDto(this Device device, bool canEdit)
{
    return new DeviceDto(
        device.DeviceId,
        device.Name,
        //... a bunch of trivial properties 
        device.DateCreated,  
        canEdit);
}

As you can see the last property (which is named CanEdit) comes from the mapping method parameter. My problem is that I can't have Mapperly handle this for me.

Describe the solution you'd like
I propose that Mapperly supports adding method parameters to the set of properties to map and mapping them by convention

Describe alternatives you've considered
I can think of several ways to work around this with an additional method but that would require adding a setter or creating a new record with "with" which means allocation and in any case that would add code that in theory can be handled by convention by the mapper

Do you think this would be a reasonable feature that is worth implementing?

P.S. Thanks for the great library, I particularly like how it tends to write the mappings very close to the style that I arrived at myself doing manual mapping.

@Eirenarch Eirenarch added the enhancement New feature or request label Aug 6, 2024
@latonz
Copy link
Contributor

latonz commented Aug 6, 2024

This looks like a duplicate of #103. This was implemented recently and should work as of 4.0.0-next.2.

@latonz latonz closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2024
@Eirenarch
Copy link
Author

Yes, it is. I only checked the open issues. Sorry for wasting your time.

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

No branches or pull requests

2 participants