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

跟風遠走 提交于 2019-11-28 23:32:23

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

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!