C#反射创建对象
程序由人 2009-03-21 11:12:26 public sealed class DataAccess
{
private static readonly string path = System.Configuration.ConfigurationSettings.AppSettings["DAL"];
/// <summary>
/// 创建对象或从缓存获取
/// </summary>
public static object CreateObject(string path, string CacheKey)
{
object objType = DataCache.GetCache(CacheKey);//从缓存读取
if(objType == null)
{
try
{
objType = Assembly.Load(path).CreateInstance(CacheKey);//反射创建
DataCache.SetCache(CacheKey, objType);//写入缓存
}
catch
{ }
}
return objType;
}
object objType = DataCache.GetCache(CacheKey);//从缓存读取
//问题在这里:这句计算机根本不去执行,不知道为什么,调试了N次objType始终是NULL,我的path和CacheKey都不是空的。为什么总是NULL?