1

Closed

Converting Nullable Types

description

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 >()
.ConvertUsing(
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 >()
.ConvertUsing(
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

comments

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.