简单的拷贝对象类

 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;
        }
    }

  

  

原文地址:https://www.cnblogs.com/garysun90/p/3956144.html