日期:2014-05-17 浏览次数:21049 次
public struct User
{
public int id;
public string name;
........
}
public struct User
{
public int id;
public string name;
}
static void Main(string[] args)
{
Type type = typeof(User);
FieldInfo[] fileds = type.GetFields();
foreach (FieldInfo f in fileds)
{
Console.WriteLine(f.Name);//id name
}
}
public void GetVal(object obj)
{
Type type = obj.GetType();
PropertyInfo[] pros = type.GetProperties();
foreach (PropertyInfo p in pros)
{
Console.WriteLine(p.GetValue(obj, null));
}
}