C # class inheritance value assigned
/// <summary>
/// 将父类的值赋值到子类中
/// </summary>
/// <typeparam name="TParent"></typeparam>
/// <typeparam name="TChild"></typeparam>
/// <param name="parent"></param>
/// <param name="child"></param>
public static void CopyToChild<TParent, TChild>(TParent parent, TChild child)
{
var ParentType = typeof(TParent);
var Properties = ParentType.GetProperties();
foreach (var Propertie in Properties)
{
// Loop through property
IF (Propertie.CanRead && Propertie.CanWrite)
{
// attribute copy
Propertie.SetValue (Child, Propertie.GetValue (parent, null ), null );
}
}
}