Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The reason the <code>FormCollectionValueResolver&lt;Customer&gt;</code> never gets called is that the <code>ForAllMembers()</code> method iterates over all your property mappings, as defined by the <code>ForMember()</code> method, applying the specified member options. However, in the code sample you supplied no property mappings have been defined, thus the resolver never gets called.</p> <p>Here is an example of how the <code>ForAllMembers()</code> method could be used.</p> <pre><code>[Test] public void AutoMapperForAllMembersTest() { Mapper.CreateMap&lt;Source, Destination&gt;() .ForMember(dest =&gt; dest.Sum, opt =&gt; opt.ResolveUsing&lt;AdditionResolver&gt;()) .ForMember(dest =&gt; dest.Difference, opt =&gt; opt.ResolveUsing&lt;SubtractionResolver&gt;()) .ForAllMembers(opt =&gt; opt.AddFormatter&lt;CustomerFormatter&gt;()); Source source = new Source(); source.Expression = new Expression { LeftHandSide = 2, RightHandSide = 1 }; Destination destination = Mapper.Map&lt;Source, Destination&gt;(source); Assert.That(destination.Sum, Is.EqualTo("*3*")); Assert.That(destination.Difference, Is.EqualTo("*1*")); } public class Expression { public int LeftHandSide { get; set; } public int RightHandSide { get; set; } } public class Source { public Expression Expression { get; set; } } public class Destination { public string Sum { get; set; } public string Difference { get; set; } } public class AdditionResolver : ValueResolver&lt;Source, int&gt; { protected override int ResolveCore(Source source) { Expression expression = source.Expression; return expression.LeftHandSide + expression.RightHandSide; } } public class SubtractionResolver : ValueResolver&lt;Source, int&gt; { protected override int ResolveCore(Source source) { Expression expression = source.Expression; return expression.LeftHandSide - expression.RightHandSide; } } public class CustomerFormatter : IValueFormatter { public string FormatValue(ResolutionContext context) { return string.Format("*{0}*", context.SourceValue); } } </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