![](/img/trans.png)
[英]copy an attribute of a property from one instance to another instance (of a different type ) at runtime
[英]Copy data from one class instance to another class instance having same property names but different property types
我有两个属性名称相同但类型不同的类,即一个类具有字符串属性,另一个类具有用户定义类型的属性,我想将数据从一个类复制到另一个类,所以,这可能吗? 请提出解决方案
感谢致敬。
您不能期望 .net 框架能够为您做所有事情。 创建一个将源类作为参数的方法,创建目标类的实例,复制属性(只有您知道如何映射和转换)并返回新对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.