Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tested this code and got this working using the following code:</p> <pre><code>public void TestMethod1() { Mapper.CreateMap&lt;string, DateTime&gt;().ConvertUsing(new DateTimeTypeConverter()); Mapper.CreateMap&lt;string, Type&gt;().ConvertUsing(new StringTypeConverter()); Mapper.CreateMap&lt;string, int&gt;().ConvertUsing(new StringIntConverter()); Mapper.CreateMap&lt;Source, Destination&gt;(); var destination = Mapper.Map&lt;Source, Destination&gt;( new Source { Value1 = "15", Value2 = "01/01/2000", Value3 = "System.String" }, options =&gt; options.ConstructServicesUsing(type =&gt; new SourceDestinationTypeConverter()) ); Assert.AreEqual(destination.Value2.Year, 2000); } </code></pre> <p>And the extra Converters:</p> <pre><code> public class StringTypeConverter : ITypeConverter&lt;string, Type&gt; { public Type Convert(ResolutionContext context) { return Type.GetType(context.SourceValue.ToString()); } } public class StringIntConverter : ITypeConverter&lt;string, int&gt; { public int Convert(ResolutionContext context) { return Int32.Parse(context.SourceValue.ToString()); } } </code></pre> <p>Automapper was missing a mapping for String to Type and String to Int. Also I had to remove the following line</p> <pre><code>Mapper.CreateMap&lt;Source, Destination&gt;().ConstructUsingServiceLocator(); </code></pre> <p>and replace it by</p> <pre><code>Mapper.CreateMap&lt;Source, Destination&gt;(); </code></pre> <p>I'm not aware of the "ConstructUsingServiceLocator()" option, but leaving it out works in this case... (I have no idea whether leaving it out will bring up other issues for u. Until now I have not yet used this option when working with Automapper.)</p> <p>Please note I had to add the "Value3" parameter since the convertion would fail... Converting a NULL value to a Type can be pretty hard... (And I am not aware of what kind of conversion has to happen here...)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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