using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication2.Models;
using DataAccess;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
namespace MvcApplication2.Controllers
{
 

    public class GenericList<T>:List<T>
    {
        public GenericList(DataTable dt, string  f)
        {
            System.Type tt = System.Type.GetType(f);//获取指定名称的类型
            object ff = Activator.CreateInstance(tt, null);//创建指定类型实例
            PropertyInfo[] fields = ff.GetType().GetProperties();//获取指定对象的所有公共属性
            foreach (DataRow dr in dt.Rows)
            {
                object obj = Activator.CreateInstance(tt, null);
                foreach (DataColumn dc in dt.Columns)
                {
                    foreach (PropertyInfo t in fields)
                    {
                        if (dc.ColumnName == t.Name)
                        {
                            t.SetValue(obj, dr[dc.ColumnName], null);//给对象赋值
        

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2022-03-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-22
  • 2022-12-23
  • 2021-09-28
  • 2021-08-23
  • 2022-12-23
  • 2022-01-19
相关资源
相似解决方案