反射

反射
 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;

        }
反射

反射

上一篇:ref & out


下一篇:C#字符串比较