本帖最后由 yi_piao 于 2014-04-28 11:32:54 编辑

解决方案 »

  1.   

    xxx xxxEntity = new xxx(); //这个功能怎么实现。
    T t = new T()public class Parent
    {
     public  string  PropertyA  {get; set}
    }public static List<xxx> Method(List<xxx> listXxx) where xxx : Parent 泛型约束
    xxEntity.PropertyA = value; //泛型约束,由父类或接口定义属性 那么xxx才有明确的属性
      

  2.   


    根据你的提示,搞定了,谢谢。给后来人做参考,把搞定后的代码贴上来,本来是实现数据访问层的一个通用查询方法。using System;
    using System.Configuration;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Reflection;namespace S6.Data
    {
        internal class DataHandler<T> where T:new ()
        {
            private static SqlConnection con = null;
            private static string conString = ConfigurationManager.ConnectionStrings["bmcConnection"].ConnectionString;        public static List<T> ExcuteList(SqlCommand cmd)
            {
                con=new SqlConnection(conString);
                cmd.Connection = con;
                List<T> listEntity = new List<T>();            try
                {
                    con.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        T entity = new T();
                        Type t = entity.GetType();
                        foreach (PropertyInfo pi in t.GetProperties())
                        {
                            pi.SetValue(entity, reader[pi.Name],null);
                        }
                        listEntity.Add(entity);
                    }
                    reader.Close();
                }
                catch
                {
                    throw new Exception("在数据库中获取列表导常。");
                }
                finally
                {
                    con.Close();
                }            return listEntity;
            }
        }
    }
      

  3.   

    List<object> 作为参数!
      

  4.   

    你要的不就是Mapper么。这个网上有现成的第三方开源dll,支持程度比你这个高多了