MapsterMapper / MapsterMapper/Mapster
Compile doesn't throw exceptions while configuring with attributes
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.2k
- Forks
- 410
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
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(); // Exception: corresponding source member mapped or ignored:Title
```
On the other hand, if I configure using an interface:
`IMapFrom`
or utilize the method:
`TypeAdapterConfig.GlobalSettings.ForType();`
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the [AdaptFrom] configuration and compare it with IMapFrom and ForType() during Compile(). Reproduce the records example with RequireDestinationMemberSource enabled, then trace when the missing Title member is validated. Done means Compile() reports the same missing-member error for attribute configuration as it does for the other two paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100