Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you only need to map from <code>CertMail</code> to <code>CertMailReceipt</code> and the two types are very similar, you could use an automagic helper like <a href="http://automapper.codeplex.com" rel="nofollow noreferrer">AutoMapper</a> to help you with the mapping.</p> <p>Basically, AutoMapper will handle much of the boring and error-prone left-right code - assigning one property on the target to a property on the source object.</p> <p>In your case, if the two types are somewhat similar, you could do something like:</p> <pre><code>using AutoMapper; Mapper.CreateMap&lt;CertMail, CertMailReceipt&gt;(); sourceList.ForEach(certMail =&gt; { lsReceiptNumbers.Add(Mapper.Map&lt;CertMail, CertMailReceipt&gt;(certMail)) }); </code></pre> <p>or if you prefer:</p> <pre><code>using AutoMapper; Mapper.CreateMap&lt;CertMail, CertMailReceipt&gt;(); foreach(certMail cm in sourceList) { lsReceiptNumbers.Add(Mapper.Map&lt;CertMail, CertMailReceipt&gt;(cm)); } </code></pre> <p>This is basically the same idea that NPayette mentioned, just using an half-automatic mapper, instead of having to write the whole mapping process yourself.</p> <p>And with a bit of luck (and depending on your types of data structures), you might even get the benefit of Automapper being able to even map entire lists from one type to another:</p> <pre><code>lsReceiptNumbers = Mapper.Map&lt;List&lt;CertMail&gt;, List&lt;CertMailReceipt&gt;&gt;(sourceList); </code></pre> <p>Automapper will go through the list of items itself, and apply its mapping to each item, and add those to the resulting output list.</p>
 

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