自动输出类的字段值实用代码分享_C#教程-查字典教程网
自动输出类的字段值实用代码分享
自动输出类的字段值实用代码分享
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:usingSystem;usingSystem.Linq;usingSystem.Reflection;namespace...

复制代码 代码如下:

using System;

using System.Linq;

using System.Reflection;

namespace LucienBao.Common

{

public static class ToStringHelper

{

public static string ToString(object obj)

{

Type t = obj.GetType();

FieldInfo[] fis = t.GetFields();

return string.Join(Environment.NewLine,

fis.Select<FieldInfo, string>

(p => p.Name + ":" + p.GetValue(obj).ToString()).ToArray()

);

}

}

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新C#教程学习
    热门C#教程学习
    编程开发子分类