C# 版的 var_dump

///<summary>
/// equiv of PHP's var dump for an object’s properties because i cbf writing all the properties out.
///</summary>
///<param name="info"></param>
private static string var_dump(object info)
{
StringBuilder sb
= new StringBuilder();

Type t
= info.GetType();
PropertyInfo[] props
= t.GetProperties();
sb.AppendFormat(
"{0,-18} {1}", "Name", "Value");
sb.AppendLine();
foreach (PropertyInfo prop in props)
{
sb.AppendFormat(
"{0,-18} {1}", prop.Name, prop.GetValue(info, null).ToString());
sb.AppendLine();
}

return sb.ToString();
}

posted @ 2011-04-14 16:59  梦幻泡影  阅读(1580)  评论(0编辑  收藏  举报