using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Face.Services.Tool
{
///
/// 实体帮助
///
public static class ModelHelper
{
///
/// 获取实体属性名
///
///
public static string GetModelPropertyName() where T : class, new()
{
string nameStr = "";
foreach (PropertyInfo pi in (new T()).GetType().GetProperties())
{
//获得属性的名字,后面就可以根据名字判断来进行些自己想要的操作
var name = pi.Name;
//var value = pi.GetValue(list, null);//用pi.GetValue获得值
//var type = value?.GetType() ?? typeof(object);//获得属性的类型
nameStr += "`" + name + "`,";
}
return nameStr.Substring(0, nameStr.Length - 1);//nameStr; 去除最后一个逗号
}
public static List> TableToRow(DataTable tbl)
{
List> rows = new List>();
foreach (DataRow Row in tbl.Rows)//循环行
{
Dictionary row = new Dictionary();
for (int i = 0; i < Row.ItemArray.Length; i++)
{
row.Add(tbl.Columns[i].ColumnName, Row[i].ToString());
}
rows.Add(row);
}
return rows;
}
}
}