您的位置:首页 > 其它

2015-12-29 工作笔记-2

2015-12-29 13:00 323 查看
1、通过属性字段获得属性的值

//根据属性字段获得属性值
public string GetObjectPropertyValue<T>(T t, string propertyname)
{
Type type = typeof(T);
PropertyInfo property = type.GetProperty(propertyname);
if (property == null) return string.Empty;
object o = property.GetValue(t, null);
if (o == null) return string.Empty;
return o.ToString();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: