public static void Fill<T>(IDataReader sdr, T entity)
    {
        for (int i = 0; i < sdr.FieldCount; i++)
        {
            PropertyInfo pi = entity.GetType().GetProperty(sdr.GetName(i));
            if (pi != null)
            {
                if (sdr.GetValue(i) != DBNull.Value)
                {
                    pi.SetValue(entity, sdr.GetValue(i), null);
                }
            }
        }
    }
    public static IList<T>  EnumDataReader<T>( IDataReader idr)
    {
        IList<T> IL = new List<T>();
        while (idr.Read())
        {
            T entiy = Activator.CreateInstance<T>();
            Fill<T>(idr,entiy);
            IL.Add(entiy);
        }
        return IL;
    }
 posted on 2008-11-02 01:08  隔山打牛  阅读(164)  评论(0编辑  收藏  举报