src/YL.Utils/Extensions/CollectionExt.cs
(开头部分) 7KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Text;
using YL.Utils.Reflection;
namespace YL.Utils.Extensions
{
public static class CollectionExt
{
public static List<T> EmitToList<T>(this DataTable dt)
{
//确认参数有效
if (dt == null)
return null;
List<T> list = new List<T>();
var objBuilder = EmitUtil.CreateBuilder(typeof(T));
for (int i = 0; i < dt.Rows.Count; i++)
{
//创建泛型对象
T _t = (T)objBuilder();
//获取对象所有属性
PropertyInfo[] propertyInfo = _t.GetType().GetProperties();
for (int j = 0; j < dt.Columns.Count; j++)
{
foreach (PropertyInfo info in propertyInfo)
{
//属性名称和列名相同时赋值
if (dt.Columns[j].ColumnName.ToUpper().Equals(info.Name.ToUpper()))
{
if (dt.Rows[i][j] != DBNull.Value)
{
info.SetValue(_t, dt.Rows[i][j], null);
}
else
{
info.SetValue(_t, null, null);
}
break;
}
}
}
list.Add(_t);
}
return list;
}
public static List<T> ToList<T>(this DataTable dt)
{
List<T> list = new List<T>();
//确认参数有效,若无效则返回Null
if (dt == null)
return list;
else if (dt.Rows.Count == 0)
后面还有 138 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。