ASP.NET反射


        public static string ToIds<T>(this List<T> list, string filedName)
        {
            if (list.Count() > 0)
            {
                StringBuilder sBuilder = new StringBuilder();
                PropertyInfo[] properties = list[0].GetType().GetProperties();
                foreach (var v in list)
                    sBuilder.AppendFormat("'{0}',", properties.FirstOrDefault(x => x.Name == filedName).GetValue(v, null));
                sBuilder.Length -= 1;
                return sBuilder.ToString();
            }
            else return null;
        }

posted @ 2012-03-23 19:58  wangsufei  阅读(168)  评论(0编辑  收藏  举报