一个方法通过T 返回指定 数据库列表

       
      public static FeedBack<List<T>> GetDataLlist<T>(int PageNow, int PageSize, out int TotalNum) where T : class
        {
            FeedBack<List<T>> Result = new FeedBack<List<T>>();
            TotalNum = 0;
            if (typeof(T) == typeof(houseBillInfo))
            {
                return (FeedBack<List<T>>)(object)GetPayBillList(PageNow, PageSize, out TotalNum);
            }
            if (typeof(T) == typeof(houseBillInfo))
            {
                return (FeedBack<List<T>>)(object)GetPayBillList(PageNow, PageSize, out TotalNum);
            }


            return Result;
        }


        public static FeedBack<List<T>> GetDataLlist<T>(int HouseId, int PageNow, int PageSize, out int TotalNum) where T : class
        {
            FeedBack<List<T>> Result = new FeedBack<List<T>>();
            TotalNum = 0;
            if (typeof(T) == typeof(houseBillInfo))
            {
                //return (FeedBack<List<T>>)(object)GetPayBillList(HouseId, PageNow, PageSize, out TotalNum);
                return ConvertTo<FeedBack<List<T>>>(GetPayBillList(HouseId, PageNow, PageSize, out TotalNum));
            }
            if (typeof(T) == typeof(houseBillInfo))
            {
                //return (FeedBack<List<T>>)(object)GetPayBillList(HouseId, PageNow, PageSize, out TotalNum);
                return ConvertTo<FeedBack<List<T>>>(GetPayBillList(HouseId, PageNow, PageSize, out TotalNum));
            }


            return Result;
        }

        static T ConvertTo<T>(object val)
        {
            try
            {
                return (T)Convert.ChangeType(val, typeof(T));
            }
            catch
            {
                return default(T);
            }
        }        


猜你喜欢

转载自blog.csdn.net/sinat_30224769/article/details/80087676