MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.3k stars 328 forks source link

AddParameters not working #518

Closed GihanSoft closed 1 year ago

GihanSoft commented 1 year ago

This is not working. Id is '0'

var c1 = new Class1("title1");
var c2 = c1.BuildAdapter()
    .AddParameters("Id", 1) //this or below one or both, non of them works
    .AddParameters("id", 2)
    .AdaptToType<Class2>();

Console.WriteLine(c2);
// output:
// Class2 { Id = 0, Title = title1 }

record Class1(string Title);
record Class2(int Id, string Title);
andrerav commented 1 year ago

AddParameters() work just fine. But you are missing some required configuration to make this work:

TypeAdapterConfig<Class1, Class2>.NewConfig()
                            .Map(dest => dest.Id,
                                    src => MapContext.Current.Parameters["Id"]);

More information here: https://github.com/MapsterMapper/Mapster/wiki/Setting-values