Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Without looking I suspect its calling your <code>TypeCoverter</code> because its the best match for the types being converted.</p> <p>If you create another <code>TypeConverter</code> with the correct types it should work fine. Eg:</p> <pre class="lang-cs prettyprint-override"><code>public class DateTimeConverter : ITypeConverter&lt;DateTime?, DateTime&gt; { public DateTime Convert(ResolutionContext context) { var sourceDate = context.SourceValue as DateTime?; if (sourceDate.HasValue) return sourceDate.Value; else return default(DateTime); } } public class NullableDateTimeConverter : ITypeConverter&lt;DateTime?, DateTime?&gt; { public DateTime? Convert(ResolutionContext context) { var sourceDate = context.SourceValue as DateTime?; if (sourceDate.HasValue) return sourceDate.Value; else return default(DateTime?); } } </code></pre> <p>Note that if you wish these can be further simplified to</p> <pre class="lang-cs prettyprint-override"><code>public class DateTimeConverter : TypeConverter&lt;DateTime?, DateTime&gt; { protected override DateTime ConvertCore(DateTime? source) { if (source.HasValue) return source.Value; else return default(DateTime); } } public class NullableDateTimeConverter : TypeConverter&lt;DateTime?, DateTime?&gt; { protected override DateTime? ConvertCore(DateTime? source) { return source; } } </code></pre> <p>Then just initialise both converters:</p> <pre class="lang-cs prettyprint-override"><code>Mapper.CreateMap&lt;DateTime?, DateTime&gt;().ConvertUsing&lt;DateTimeConverter&gt;(); Mapper.CreateMap&lt;DateTime?, DateTime?&gt;().ConvertUsing&lt;NullableDateTimeConverter&gt;(); Mapper.AssertConfigurationIsValid(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload