首页 > 其他 > 详细

简单的拷贝对象类

时间:2014-09-04 16:37:59      阅读:272      评论:0      收藏:0      [点我收藏+]
 public static class TypeHelper
    {
        public static TP AutoCopy<TP, TC>(TC source) where TP : new()
        {
            TP dest = new TP();

            var ParentType = typeof(TP);

            var Properties = ParentType.GetProperties();

            foreach (var Propertie in Properties)
            {
                if (Propertie.CanRead && Propertie.CanWrite)
                {
                    Propertie.SetValue(dest, Propertie.GetValue(source, null), null);
                }
            }

            return dest;
        }
        public static TP AutoCopy<TP, TC>(TP dest, TC source) where TP : new()
        {
            var ParentType = typeof(TP);

            var Properties = ParentType.GetProperties();

            foreach (var Propertie in Properties)
            {
                if (Propertie.CanRead && Propertie.CanWrite)
                {
                    Propertie.SetValue(dest, Propertie.GetValue(source, null), null);
                }
            }

            return dest;
        }
    }

  

  

简单的拷贝对象类

原文:http://www.cnblogs.com/garysun90/p/3956144.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!