获取Model的所有属性字符串

 

 

   /// <summary>
        /// 返回属性字段,作用是Sql查询的时候用来替换 * , *查询会影响运行速度
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <returns></returns>
        public string GetModelSqlstr<T>()
        {
            string RtnStr = string.Empty;
            try
            {

                Type entityType = typeof(T); 
                System.Reflection.PropertyInfo[] properties = entityType.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

                foreach (PropertyInfo item in properties)
                {
                    RtnStr = string.Format("{0},{1}", RtnStr, item.Name);
                }
                RtnStr = " "+RtnStr.TrimEnd(',').TrimStart(',')+" ";
            }
            catch (Exception)
            {

                throw;
            }

            return RtnStr;
        }

 

   /// <summary>        /// 返回属性字段,作用是Sql查询的时候用来替换 * , *查询会影响运行速度       /// </summary>       /// <typeparam name="T"></typeparam>       /// <returns></returns>        public string GetModelSqlstr<T>()        {            string RtnStr = string.Empty;            try            {
                Type entityType = typeof(T);                 System.Reflection.PropertyInfo[] properties = entityType.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                foreach (PropertyInfo item in properties)                {                    RtnStr = string.Format("{0},{1}", RtnStr, item.Name);                }                RtnStr = " "+RtnStr.TrimEnd(',').TrimStart(',')+" ";            }            catch (Exception)            {
                throw;            }
            return RtnStr;        }

posted @ 2019-06-20 14:41  人生为卒  阅读(436)  评论(0编辑  收藏  举报