反射打印类的所有属性值
2016-01-30 18:15:06 访问(1615) 赞(0) 踩(0)
/// <summary>
/// 反射打印类的所有属性值
/// </summary>
/// <returns></returns>
public string ToInfoString(object oThis)
{
if (oThis == null)
return "";
Type thisType = oThis.GetType();
PropertyInfo[] pA = thisType.GetProperties();
StringBuilder theResult = new StringBuilder();
object oValue = null;
foreach (PropertyInfo info in pA)
{
if (!info.CanRead)
continue;
oValue = info.GetValue(oThis, null);
theResult.Append(info.Name + "=");
if (oValue == null)
theResult.AppendLine();
else
theResult.AppendLine(oValue.ToString());
}
return theResult.ToString();
}
标签:
反射打印类的所有属性值 


上一条:
下一条:
相关评论
发表评论