读书人

asp.net网站项目中运用Type.GetType获

发布时间: 2013-09-06 10:17:17 作者: rapoo

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;

读书人网 >C#

热点推荐