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 IMapFrom interface for automatic mapping configuration #533

Merged
merged 1 commit into from
Feb 7, 2023

Conversation

stormaref
Copy link
Contributor

Creating IMapFrom interface
now destination type can inherit from an interface named IMapFrom and they can configure mapping in the same class like this:

public class InheritedDestinationModel : IMapFrom<SourceModel>
{
    public string Type { get; set; }
    public int Value { get; set; }

    public void ConfigureMapping(TypeAdapterConfig config)
    {
        config.NewConfig<SourceModel, InheritedDestinationModel>()
            .Map(dest => dest.Value, _ => DesireValues.Number);
    }
}

and even if you don't implement the method it will automatically create a new config for desire types
ex:

public class DestinationModel : IMapFrom<SourceModel>
{
    public string Type { get; set; }
}

I've added a new extension method to TypeAdapterConfig named ScanInheritedTypes like this:

TypeAdapterConfig.GlobalSettings.ScanInheritedTypes(Assembly.GetExecutingAssembly());

I've created tests for all situations and tests are passed
as soon as this pull request merged I will update wiki page

@stormaref stormaref changed the title add IMapFrom interface Add IMapFrom interface for automatic mapping configuration Feb 2, 2023
@andrerav andrerav merged commit 65b6466 into MapsterMapper:master Feb 7, 2023
@andrerav
Copy link
Contributor

andrerav commented Feb 7, 2023

Thanks @stormaref!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants