Object copy approaches in .net: Auto Mapper, Emit Mapper, Implicit Operation, Property Copy

后端 未结 3 1369
无人及你
无人及你 2020-12-16 00:02

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?

Here is the tests of d

相关标签:
3条回答
  • 2020-12-16 00:37

    Have you tried overriding the Clone method to copy object instances? This way, you get a new student object like this:

    for (int i = 0; i < 1000000; i++) 
    { 
         StudentDTO itemT = _student.Clone(); 
    }
    

    I find this approach the easiest way of copying objects into new objects, though I haven't done any speed tests to find out how well it performs against the methods you suggest.

    0 讨论(0)
  • 2020-12-16 00:46

    It is also possible to use T4 to generate classes that will generate property copy code.

    Good: runs as fast as it is possible Bad: "coding" in T4 Ugly: Making build scripts that allow you to compile it all in one go

    0 讨论(0)
  • 2020-12-16 00:47

    the Clone is for copy the same Type not for copying from 2 different objects Type then can't be used for this scope.

    0 讨论(0)
提交回复
热议问题