代码:
Type type = dgParent.GetType();//获取对象类型
PropertyInfo[] props = type.GetProperties();//获取属性集合 String result = string.Empty;
foreach (var item in props)//遍历属性输出结果
{
result = string.Format(@"{0}
{1}:{2}", result, item.Name, item.GetValue(dgParent) == null ? string.Empty : item.GetValue(dgParent).ToString());
}
效果: