/// 將Datatable轉換為泛型列表對象
/// </summary>
/// <typeparam name=
/// <param name=
/// <returns>目標泛型列表對象</returns>
protected List<T> DataTableToList<T>(DataTable dataTable)
{
List<T> list = new List<T>()
Type targetType=typeof(T)
PropertyInfo[] allPropertyArray = targetType
foreach (DataRow rowElement in dataTable
{
T element=Activator
foreach (DataColumn columnElement in dataTable
{
foreach (PropertyInfo property in allPropertyArray)
{
if(property
{
if (rowElement[columnElement
{
property
}
else
{
property
[columnElement
}
}
}
}
list
}
return list;
}
From:http://tw.wingwit.com/Article/program/net/201311/11812.html