asp.net网站项目中使用Type.GetType获取对象为NULL
类均在APP_Code文件夹中
定义了一个借口:
public interface IMethodExample
{
string Method();
}
一个类:
public class MethodExample: IMethodExample
{
public string Method()
{
string str = " 1234567 ";
return str;
}
}
在APSX.CS的Page_Load事件里
IMethodExample tt= Type.GetType("MethodExample") as IMethodExample;
Response.Write(tt == null);
输出结果True
加上命名空间也不行。
在网站项目里无法使用这个么。
[解决办法]
肯定获取不到啊,你都没有实例化一个IMethodExample对象啊
[解决办法]
IMethodExample tt = Activator.CreateInstance(Type.GetType("命名空间.MethodExample")) as IMethodExample;