Skip to content

Union two models in new model. #989

Closed Answered by latonz
Zombach asked this question in Q&A
Discussion options

You must be logged in to vote

You can use existing target mappings (as mentioned by @TimothyMakkison) in combination with AllowNullPropertyAssignment = false, this should work to merge objects where all source properties are nullable.

[Mapper(AllowNullPropertyAssignment = false)]
static partial class Mapper
{
    public static partial void Merge(A source, B target);
}

// generates
public static partial void Merge(global::A source, global::B target)
{
    if (source.V != null)
    {
        target.V = source.V;
    }
    if (source.V2 != null)
    {
        target.V2 = source.V2;
    }
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Zombach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants