自动输出类的字段值实用代码分享
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()
);
}
}
}
最新评论