随笔- 5  文章- 14  评论- 4 
2008年11月2日
    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 @ 2008-11-02 01:08 隔山打牛 阅读(33) 评论(0) 编辑