自动输出类的字段值实用代码分享
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()
);
}
}
}
上一篇:asp.net DataSet转换成josn并输出示例
栏 目:.NET代码
下一篇:ASP.NET MVC结合JavaScript登录、校验和加密
本文标题:自动输出类的字段值实用代码分享
本文地址:http://www.codeinn.net/misctech/102946.html






