从类和反射中获取属性列表

时间:2014-10-07 15:06:26

标签: c# .net reflection properties

我试图找出如何列出会话变量中的类的属性,并且没有运气

我知道我可以在通用处理程序

中实例化这样的类
IAdvanceUser user = context.Session["advUser"] as IAdvanceUser;

或类似于aspx

IAdvanceUser user = new.SunGardHE.WebFramework.Security.AdvanceUser();

但我似乎可以从这个SO How to get the list of properties of a class?

中得到反思
IAdvanceUser user = new.SunGardHE.WebFramework.Security.AdvanceUser();
foreach(var prop in user.GetType().GetProperties()) {
    Console.WriteLine("{0}={1}", prop.Name, prop.GetValue(user, null));
}

它没有错误,但也没有显示任何输出

0 个答案:

没有答案