码迷,mamicode.com
首页 > 其他好文 > 详细

父类的属性赋值给子类的方法

时间:2016-05-26 16:06:16      阅读:398      评论:0      收藏:0      [点我收藏+]

标签:

遍历父类的属性赋值给子类的方法:

 
    1. private static ChildClass AutoCopy(ParentClass parent)  
    2.        {  
    3.            ChildClass child = new ChildClass();  
    4.   
    5.   
    6.            var ParentType = typeof(ParentClass);  
    7.   
    8.   
    9.            var Properties = ParentType.GetProperties();  
    10.   
    11.   
    12.            foreach (var Propertie in Properties)  
    13.            {  
    14.                if (Propertie.CanRead && Propertie.CanWrite)  
    15.                {  
    16.                    Propertie.SetValue(child, Propertie.GetValue(parent, null), null);  
    17.                }  
    18.            }  
    19.   
    20.   
    21.            return child;  
    22.        }  

父类的属性赋值给子类的方法

标签:

原文地址:http://www.cnblogs.com/gaobw/p/5531447.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!