遍历对象属性值

Posted lsgcontrol

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了遍历对象属性值相关的知识,希望对你有一定的参考价值。

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

   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)}
"); 
            }
            return app.ToString().Trim(‘,‘);
        }

  

以上是关于遍历对象属性值的主要内容,如果未能解决你的问题,请参考以下文章