Skip to content

Mapping configuration does not support init #121

Description

@richardluinfo

Hi Tim,

Thanks a lot for providing the support to nested facets feature. There is another challenge we are facing when trying to configure custom mapping.

Basically static abstract void Map(TSource source, TTarget target); does not seem to support immutable properties using init.

For example, the below

public record Person
{
    public required string FirstName { get; init; }
    public required string LastName { get; init; }
}

[Facet(typeof(Person), Configuration = typeof(PersonMapper))]
public partial record PersonDto
{
    public string FullName { get; init; } = string.Empty;
}

public class PersonMapper : IFacetMapConfiguration<Person, PersonDto>
{
    public static void Map(Person source, PersonDto target)
    {
        target = target with
        {
            FullName = $"{source.FirstName} {source.LastName}"
        };
    }
}

Would you consider to extend the interface to support the Map method with return value? It could be something like this:

public class PersonMapper : IFacetMapConfiguration<Person, PersonDto>
{
    public static void Map(Person source, PersonDto target)
    {
    }
    
    public static PersonDto MapTo(Person source, PersonDto target)
    {
        return target with
        {
            FullName = $"{source.FirstName} {source.LastName}"
        };
    }
}

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions