Esempio n. 1
0
        /// <summary>
        /// Reader转成List《T》
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="dr"></param>
        /// <param name="isClose"></param>
        /// <returns></returns>
        internal static List <T> DataReaderToList <T>(Type type, IDataReader dr, string fields, bool isClose = true, bool isTry = true)
        {
            if (type.Name.Contains("KeyValuePair"))
            {
                List <T> strReval = new List <T>();
                FillValueTypeToDictionary(type, dr, strReval);
                return(strReval);
            }
            //值类型
            else if (type.IsValueType || type == SqlSugarTool.StringType)
            {
                List <T> strReval = new List <T>();
                FillValueTypeToDr <T>(type, dr, strReval);
                return(strReval);
            }
            //数组类型
            else if (type.IsArray)
            {
                List <T> strReval = new List <T>();
                FillValueTypeToArray(type, dr, strReval);
                return(strReval);
            }


            var cacheManager = CacheManager <IDataReaderEntityBuilder <T> > .GetInstance();

            string key = "DataReaderToList." + fields + type.FullName;
            IDataReaderEntityBuilder <T> eblist = null;

            if (cacheManager.ContainsKey(key))
            {
                eblist = cacheManager[key];
            }
            else
            {
                eblist = IDataReaderEntityBuilder <T> .CreateBuilder(type, dr);

                cacheManager.Add(key, eblist, cacheManager.Day);
            }
            List <T> list = new List <T>();

            try
            {
                if (dr == null)
                {
                    return(list);
                }
                while (dr.Read())
                {
                    list.Add(eblist.Build(dr));
                }
                if (isClose)
                {
                    dr.Close(); dr.Dispose(); dr = null;
                }
            }
            catch (Exception ex)
            {
                if (isClose)
                {
                    dr.Close(); dr.Dispose(); dr = null;
                }
                throw ex;
            }
            return(list);
        }
Esempio n. 2
0
 /// <summary>
 /// 获取type属性cache
 /// </summary>
 /// <param name="type"></param>
 /// <param name="cachePropertiesKey"></param>
 /// <param name="cachePropertiesManager"></param>
 /// <returns></returns>
 internal static PropertyInfo[] GetGetPropertiesByCache(Type type, string cachePropertiesKey, CacheManager <PropertyInfo[]> cachePropertiesManager)
 {
     PropertyInfo[] props = null;
     if (cachePropertiesManager.ContainsKey(cachePropertiesKey))
     {
         props = cachePropertiesManager[cachePropertiesKey];
     }
     else
     {
         props = type.GetProperties();
         cachePropertiesManager.Add(cachePropertiesKey, props, cachePropertiesManager.Day);
     }
     return(props);
 }