Converting Nullable Types


The following did not work as I expected:
class Source
public DateTime? SomeDate {get;set;}
class Destination
public MyCustomDate SomeDate {get;set;}
I created a map like so:
Mapper.CreateMap<DateTime?, MyCustomDate >()
src => src.HasValue
           ? new MyCustomDate(src.Value.Day, src.Value.Month, src.Value.Year)
           : null);
However, the mapper seems to DateTime? as if it were merely DateTime. The above mapping was not used when converting from my Source to Destination.
So, I added the following:
Mapper.CreateMap<DateTime, MyCustomDate >()
src => new MyCustomDate (src.Day, src.Month, src.Year));
and then I was able to convert from ource to Destination.
Closed Jun 4, 2009 at 1:26 AM by jbogard
This one's fixed in R77


jbogard wrote May 29, 2009 at 9:12 PM

This looks to be fixed on the trunk now. I moved null behavior back to specific mappers, instead of one specific mapper for nulls. Can you give this one another go?

jbogard wrote May 29, 2009 at 9:15 PM

Ah, nevermind. I only checked DateTime? -> MyCustomDate. Source -> Destination does not work.

wrote Jun 4, 2009 at 1:26 AM

wrote Feb 22, 2013 at 12:49 AM

wrote May 16, 2013 at 11:59 AM