Skip to content

Simple way to exclude all properties of source or target class except explicitly mapped #1981

Description

@vin-igor

Is your feature request related to a problem? Please describe.
I have class A with about 70 properties and class B with 29 properties. All properties from class B exist in class A. But I want to map only 10 properties from B to A. Now I'm forced to add 19 [MapperIgnoreSource(nameof(B.Prop1))] attributes to mapper method. With this approach it is simpler to write 10 rows of manual mapping code (a.Prop2 = b.Prop2).

Maybe I'm missing somethiing but didn't find any ability to ignore all props of class with single attribute or something.

Describe the solution you'd like
It will be nice if I be able to add something like this:

[MapperIgnoreSource]
[MapProperty(nameof(B.Prop2), nameof(A.Prop2))]
[MapProperty(nameof(B.Prop3), nameof(A.Prop3))]
public static partial A Map(B b);

or one-liner (the best option):

[MapperIgnoreSource(Except=new[]{nameof(B.Prop2), nameof(B.Prop3)})]
public static partial A Map(B b);

Describe alternatives you've considered
An alternative is do not use Mapperly and write mapping myself for this cases :(

Additional context
None

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions