C# 根据列名获取列值

/// <summary>
/// 根据列名获取列值
/// </summary>
/// <param name="colName"></param>
/// <param name="item"></param>
/// <returns></returns>
public static string ObjValue2<T>(string colName, T item) where T : new()
{
object obj = "";
Type type = typeof (T);
var proInfo = type.GetProperty(colName,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
if (proInfo != null)
{
obj = proInfo.GetValue(item, null);
}
return obj.ToString();
}

posted @ 2017-05-02 09:04  zklve2  阅读(2011)  评论(0编辑  收藏  举报