获取Model的所有属性字符串

it2025-03-31  15

 

 

/// <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;        }

转载于:https://www.cnblogs.com/lhlong/p/11058627.html

最新回复(0)