首页 > 其他 > 详细

反射

时间:2014-01-24 07:55:42      阅读:333      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 public static StringBuilder GetProperties(object obj)
        {
            if (obj == null) return null;

            Type t = obj.GetType();
            PropertyInfo[] propertyInfo = t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);

            StringBuilder sb = new StringBuilder();
            foreach (PropertyInfo pInof in propertyInfo)
            {
                string strLine = pInof.Name + " = ";
                object objValue = pInof.GetValue(obj, null);

                if (objValue != null && pInof.PropertyType.IsClass && !(objValue is String))
                {
                    GetProperties(objValue);
                }
                else
                {
                    if (objValue != null)
                    {
                        strLine += objValue.ToString();

                    }
                }

                sb.AppendLine(strLine);
            }//foreach

            return sb;

        }
bubuko.com,布布扣

反射

原文:http://www.cnblogs.com/quietwalk/p/3531701.html

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