Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Compile doesn't throw exceptions while configuring with attributes

Open bugurshik opened this issue 2 years ago • 0 comments

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)

bugurshik avatar Nov 30 '23 13:11 bugurshik