遍历对象属性值

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

   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(',');
        }

  

猜你喜欢

转载自www.cnblogs.com/lsgControl/p/9237088.html