c#反射问题(winform)
艹,研究了快一天了,其实也没一天,就半天而已。出现了一个问题,没有将对象引用到示例的这个错误·找遍了所有的引用·。也没有发现问题!
代码如下
UserInfo _userinfo = UserInfoBll.Get_UserInfoModel(userid); 调用
然后继续:
using ClothingModel; //实体层
using IDataAccessLayerBase;//接口
using DataAccessLayerFactory;//工厂
namespace PMS.ClothingBll //逻辑层
public static UserInfo Get_UserInfoModel(string UserId)
{
return dal.Get_UserInfoModel(UserId);
}
如果直接点击转到定义还是没有问题的,可以跳转
---------------------------------------------
下面是工厂
using System;
using System.Web;
namespace DataAccessLayerFactory
{
public class DataCache
{
public DataCache()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///
/// </summary>
/// <param name="CacheKey"></param>
/// <returns></returns>
public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
}
/// <summary>
///
/// </summary>
/// <param name="CacheKey"></param>
/// <param name="objObject"></param>
public static void SetCache(string CacheKey, object objObject)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject);
}
}
}
-----------------------------------------------------
using ClothingModel;
using DBUtlity;
using IDataAccessLayerBase;
namespace PMS.ClothingDal
public partial class UserInfoDal : IUserInfoDALSub //继承
{
////////下面是实现代码·····
}
-----------------------------
using System;
using System.Reflection;
using IDataAccessLayerBase;
namespace DataAccessLayerFactory
{
public class DataAccessFactory
{
private static readonly string path = System.Configuration.ConfigurationManager.AppSettings["clothging"]; //------------------- 我在配置文件里面key里面填写的是这个,values写的是dal程序集的引用
private 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;
}
/// <summary>
/// 通过反射机制,实例化UserInfo接口对象。
/// </summary>
///<returns>Employee接口对象</returns>
public static IUserInfoDALSub Create_UserInfo()
{
string CacheKey = path + ".PMS.ClothingDal";
object objType = CreateObject(path, CacheKey);
return (IUserInfoDALSub)objType;
}
最后跳到逻辑层的 return dal.Get_UserInfoModel(UserId);没有引用到示例,但是我添加了引用。也没发现任何问题
有没有告诉一下原因?