Open foriequal0 opened 2 years ago
You also need a
.NewConfig<DateTimeOffset?, Timestamp>()
What would it do with .MapWith(src => new Timestamp(src.ToUnixTimeSeconds());
if src was null?
I expect it to behave same as reference types.
If DateTimeOffset
were a reference type, then dt2.Adapt<Timestamp>(config)
wouldn't return new Timestamp()
Well, I was searching for a better solution to a problem I was having with StronglyTypedIds structs and Mapster. I was trying to create a Source Generator to map the Id's automatically. What I found was a nullable version of a type was treated separately to the type, which makes sense when you do what you're doing. It would throw if you tried to do src.ToUnixTimeSeconds() when src was null.
With this fixtures,
This code doesn't work as expected.
We mitigated this issue with following code snippet:
edit: I've fixed typos in the example.