QiFeng.ZWY.Utility/DataHelper/ServicesHelper.cs
(开头部分) 9KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Reflection;
using System.Collections;
namespace QiFeng.LMSD.Utility
{
public static class ServicesHelper
{
#region DataTable - 转换为list
/// <summary>
/// DataTable转换为List
/// </summary>
public static class DataTableToListModel<T> where T : new()
{
#region DataTable - 转换为list
/// <summary>
/// 要转换的表
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static IList<T> ConvertToModel(DataTable dt)
{
if (dt == null)
return null;
IList<T> ts = new List<T>();
T t = new T();
string tempName = "";
PropertyInfo[] propertys = t.GetType().GetProperties();
foreach (DataRow row in dt.Rows)
{
t = new T();
foreach (PropertyInfo pi in propertys)
{
tempName = pi.Name;
if (dt.Columns.Contains(tempName))
{
if (!pi.CanWrite)
continue;
object value = row[tempName];
if (value != DBNull.Value)
pi.SetValue(t, value, null);
}
}
ts.Add(t);
}
return ts;
}
#endregion
}
#endregion
后面还有 206 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。