遍历对象属性值

将对象内的属性以及属性值输出

   public static string ToProperties_V(this object obj)
        {
            if (obj == null) return "";
            var s = obj.GetType(); 
            StringBuilder app = new StringBuilder();
            foreach (var item in s.GetProperties())
            {
                app.Append($"{item.Name}:{item.GetValue(obj)}\n"); 
            }
            return app.ToString().Trim(',');
        }

  

posted @ 2018-06-28 09:30  个人天使  阅读(177)  评论(0编辑  收藏  举报