C#反射
标签:gpo can col span dbnull 模型 datatable ble nbsp
public class ModelConvertHelperwhere T: new()
{
public static IList ConvertToModel(DataTable dt)
{
IList list = new List();
Type type = typeof(T);
string tempName = "";
foreach (DataRow dr in dt.Rows)
{
T t = new T();
//获得此模型的属性
PropertyInfo[] propertys = t.GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
{
tempName = pi.Name;
if (dt.Columns.Contains(tempName))
{
if (!pi.CanWrite)
{
continue;
}
object value = dr[tempName];
if (value != DBNull.Value)
{
pi.SetValue(t, value, null);
}
}
}
list.Add(t);
}
return list;
}
}
C#反射
标签:gpo can col span dbnull 模型 datatable ble nbsp
原文地址:https://www.cnblogs.com/liaods/p/8665466.html
文章来自:
搜素材网的
编程语言模块,转载请注明文章出处。
文章标题:
C#反射
文章链接:http://soscw.com/index.php/essay/76647.html
评论