c#简单工厂模式的反射无法创建实例,详细情况见内容
工厂大致是这样的
namespace DALFactory
{
public sealed class DataAccess
{
// Look up the DAL implementation we should be using
private static readonly string path = ConfigurationManager.AppSettings["WebDAL"]; //这里的值是 "SqlServerDAL" 是我项目里面的一个程序集 (实际是数据层)
private DataAccess() { }
public static IDAL.ICmsNews CreateCmsNews()
{
string className = path + ".CmsNews";
//IDAL.ICmsNews cmsnews = new SqlServerDAL.CmsNews();
IDAL.ICmsNews cmsnews = (IDAL.ICmsNews)Assembly.Load(path).CreateInstance(className); // 问题就出在这里 用反射, 每次都没有创建出 SqlServerDAL.CmsNews 的实例
return cmsnews;
}
}
}
求解释 在线等.......