using System;
namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
using System;
using System.Reflection;
//using System.Windows.Forms;
public class TestField
{
private int i=12;
protected string sabc = "a";
public DateTime dt = DateTime.Now;
public User objUser=new User("001","张三");
//执行这个
public static void Exec()
{
TestField tf = new TestField();
GetProperties(tf);
}
public static void GetProperties(Object t)
{
foreach (FieldInfo fi in t.GetType().GetFields(BindingFlags.Public|BindingFlags.Instance|BindingFlags.NonPublic))
{
object o = fi.GetValue(t);
if (fi.FieldType.IsClass && !(o is String))
{
GetProperties(o);
}
else
{
Console.WriteLine (String.Format("name:{0}==>value:{1}", fi.Name, o.ToString()));
}
}
}
public class User
{
public string UserId=string.Empty;
public string UserName=string.Empty;
public User(string _userId,string _userName)
{
UserId=_userId;
UserName=_userName;
}
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
TestField.Exec();
Console.Read();
}
}
}