使用工厂方法模式实现多数据库WinForm手机号码查询器
2010-04-08 00:00:00 来源:WEB开发网然后是抽象工厂DAL通过使用反射创建接口对象的实例
/// <summary>
/// 创建抽象工厂
/// </summary>
public sealed class ObjectCreate
{
/*所使用程序集*/
public static readonly string asseblyDAL = System.Configuration.ConfigurationManager.AppSettings["DAL"];
/// <summary>
/// 创建对象(不使用缓存:B/S使用)
/// </summary>
/// <param name="AssemblyPath"></param>
/// <param name="classNamespace"></param>
/// <returns></returns>
private static object CreateObject(string AssemblyPath, string classNamespace)
{
try
{
object objType = Assembly.Load(AssemblyPath).CreateInstance(classNamespace);
return objType;
}
catch
{
return null;
}
}
/// <summary>
/// 创建list接口对象
/// </summary>
/// <returns></returns>
public static CuteMobileSearch.IDAL.Ilist CreateListObj()
{
string className = asseblyDAL + ".listServices";
object obj = CreateObject(asseblyDAL, className);
return (CuteMobileSearch.IDAL.Ilist)obj;
}
}
更多精彩
赞助商链接