日期:2014-05-17 浏览次数:20417 次
/// <summary>
/// 通过传入的参数值 获取类型
/// </summary>
/// <param name="name"> 类名(不包含命名空间)</param>
/// <returns></returns>
private static Type GetImplType(string name)
{
string assemblyName = System.Configuration.ConfigurationManager.AppSettings["DataAccess"]; //获得 程序集/命名空间 的名称
string className = string.Format("{0}.{1}", assemblyName, name); //拼接 命名空间 + 类名, 使类名完整
System.Reflection.Assembly ass = System.Reflection.Assembly.Load(assemblyName); //加载程序集,使之返回 Assembly 类型
System.Type type = ass.GetType(className); //通过类名 获取 类型
return type;
}
/// <summary>
/// 获取 C_Category 类的对象实例
/// </summary>
/// <returns></returns>
public static PetShop.IDAL.ICategory GetCategoryDAL()
{
System.Type type = GetImplType("C_Category");
//借助类型 创建 对象实例 SL_Category = 实例_Category
PetShop.IDAL.ICategory SL_Category = System.Activator.CreateInstance(type) as PetShop.IDAL.ICategory;
return SL_Category; //返回对象实例
}