一个关于取类属性的问题..
下边这段代码,用来取得类的属性集体,我在vs2003中可以正常运行,转到vs2005中对"System.Reflection.PropertyInfo[] x = T.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);"这一句报一个"未将对象引用设置到对象的实例"的错误
要如何解决??为什么会出现这样的现像?
Type T = Type.GetType("Model.User");
System.Reflection.PropertyInfo[] x = T.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
namespace Model
{
public class User
{
//类定义
}
}
使用下边的方法又可以正常运行(但是我这里的程序必须用Type.GetType()来取得属性,5555.).
Type T=Typeof(Model.User)
System.Reflection.PropertyInfo[] x = T.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);