{
/// <summary>
/// 输出对象信息
/// </summary>
/// <param name="obj"></param>
public static void PrintInfo(object obj)
{
var type = obj.GetType();
var proteties = type.GetProperties();
//var proteties = type.GetFields();
Console.WriteLine(type.Name + ":");
Console.WriteLine("{");
if(type.IsValueType)
{
//值类型
Console.WriteLine("\t" + obj.ToString());
var fileds = type.GetFields();
foreach (var fieldInfo in fileds)
{
Console.WriteLine("\t" + fieldInfo.Name + ":" + fieldInfo.GetValue(obj));
}
}
else
{
//引用类型
foreach (var propertyInfo in proteties)
{
Console.WriteLine("\t" + propertyInfo.Name + ":" + propertyInfo.GetValue(obj, null));
//Console.WriteLine("\t" + propertyInfo.Name + ":" + propertyInfo.GetValue(obj));
}
}
Console.WriteLine("}");
}
}