MapsterMapper / Mapster

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

Compile doesn't throw exceptions while configuring with attributes #666

Open bugurshik opened 7 months ago

bugurshik commented 7 months ago

While im configuring with attributes

[AdaptFrom(typeof(Foo))]
public record Bar(string Title);
public record Foo(string Name);

These records are supposed to throw an error during Compile(), but it doesn't happen

TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource= true;
TypeAdapterConfig.GlobalSettings.Compile(); // successfull?? why??
var foo= new Foo("Name");
var bar= foo.Adapt<Bar>(); // Exception: corresponding source member mapped or ignored:Title

On the other hand, if I configure using an interface: IMapFrom<Foo> or utilize the method: TypeAdapterConfig.GlobalSettings.ForType<Bar, Foo>();

In this scenario, everything works fine

TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource= true;
TypeAdapterConfig.GlobalSettings.Compile(); // Exception: corresponding source member mapped or ignored:Title

Why is this happening? (lib: Mapster v7.4.0)