namespace Common.system { /// /// 数据转换帮助类 /// 创建人:赵耀 /// 创建时间:2018年10月24日 /// public class DataConvertCommon { /// /// 父类向子类赋值 /// 创建人:赵耀 /// 创建时间:2018年10月24日 /// /// 父类 /// 子类 /// 子数据 /// public static TChild ParentClassCopy(TParent parent) where TChild : TParent, new() { TChild child = new TChild(); System.Type ParentType = typeof(TParent); System.Reflection.PropertyInfo[] Properties = ParentType.GetProperties(); foreach (System.Reflection.PropertyInfo Propertie in Properties) { //循环遍历属性 if (Propertie.CanRead && Propertie.CanWrite) { //进行属性拷贝 Propertie.SetValue(child, Propertie.GetValue(parent, null), null); } } return child; } } }