Note that there are some explanatory texts on larger screens.

plurals
  1. POObject copy approaches in .net: Auto Mapper, Emit Mapper, Implicit Operation, Property Copy
    primarykey
    data
    text
    <p>If some one knows any more ways of doing this in .NET and also what is your opinions about that approaches? Which approach you choose and why?</p> <p>Here is the tests of different ways of object copy in .NET. </p> <p>Tests Related to this original thread: <a href="https://stackoverflow.com/questions/531505/how-to-copy-value-from-class-x-to-class-y-with-the-same-property-name-in-c">How to copy value from class X to class Y with the same property name in c#?</a></p> <p>So, here it is, you can run it yourself:</p> <pre><code>static void Main(string[] args) { Student _student = new Student(); _student.Id = 1; _student.Name = "Timmmmmmmmaaaahhhh"; _student.Courses = new List&lt;int&gt;(); _student.Courses.Add(101); _student.Courses.Add(121); Stopwatch sw = new Stopwatch(); Mapper.CreateMap&lt;Student, StudentDTO&gt;(); StartTest(sw, "Auto Mapper"); for (int i = 0; i &lt; 1000000; i++) { StudentDTO dto = Mapper.Map&lt;Student, StudentDTO&gt;(_student); } StopTest(sw); StartTest(sw, "Implicit Operator"); for (int i = 0; i &lt; 1000000; i++) { StudentDTO itemT = _student; } StopTest(sw); StartTest(sw, "Property Copy"); for (int i = 0; i &lt; 1000000; i++) { StudentDTO itemT = new StudentDTO { Id = _student.Id, Name = _student.Name, }; itemT.Courses = new List&lt;int&gt;(); foreach (var course in _student.Courses) { itemT.Courses.Add(course); } } StopTest(sw); StartTest(sw, "Emit Mapper"); ObjectsMapper&lt;Student, StudentDTO&gt; emitMapper = ObjectMapperManager.DefaultInstance.GetMapper&lt;Student, StudentDTO&gt;(); for (int i = 0; i &lt; 1000000; i++) { StudentDTO itemT = emitMapper.Map(_student); } StopTest(sw); } </code></pre> <p>Tests results on my PC:</p> <p>Test Auto Mapper:22322 ms</p> <p>Test Implicit Operator:310 ms</p> <p>Test Property Copy:250 ms</p> <p>Test Emit Mapper:281 ms</p> <p>You can get emit and auto -mappers from here:</p> <p><a href="http://emitmapper.codeplex.com/" rel="nofollow noreferrer">http://emitmapper.codeplex.com/</a></p> <p><a href="http://automapper.codeplex.com/" rel="nofollow noreferrer">http://automapper.codeplex.com/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    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