Assembly.Load(“Poetry.Model”).CreateInstance("Poetry.Model.BaseService<admin>");
这句话,生成的实力是BaseService,这个泛型请问,有谁碰到过吗?
Assembly.Load(“Poetry.Model”).CreateInstance("Poetry.Model.admin")
如果不是泛型的话,是可以的,关键我现在想反射出泛型,也就是这个下面这个类?请问有什么方法吗?
public class DALFactory<T> where T : class, new()
{
public static readonly string DALPath = System.Configuration.ConfigurationManager.AppSettings["DALPath"];
public static readonly string DALHZ = System.Configuration.ConfigurationManager.AppSettings["HZ"];
public static object CreateDAL(string assemblyPath, string objType)
{
object cacheDao = DALCache.GetDao(objType);
if (cacheDao == null)
{
cacheDao = Assembly.Load(assemblyPath).CreateInstance("Poetry.Model.命名空间下的泛型。怎么弄啊!");
DALCache.InsertDaoCache(objType, cacheDao);
}
return cacheDao;
}
}
既然用泛型了,为什么不直接new T():
cacheDao = new T();
如果一定要用CreateInstance,那就这样:
Assembly.Load(assemblyPath).CreateInstance(typeof(T).Name);
我就那写过了,但是还是不行啊。能帮我看下源码吗?
@Waters: 报什么错误?
@Waters: BaseService<T>应该实现IExpandDAL<T>接口:
public class BaseService<T> : IExpandDAL<T> where T : class, new()
你在GetCustomerDao中进行的操作是: as IExpandDAL<T>;