public class AbstractFactory
{
private static readonly string AssemblyPath = "DAL";//程序集;这里可以写到配置文件里。
private static readonly string NameSpase = "DAL";//命名空间;这里可以写到配置文件里。
private static object CreateInstance(string className)
{
var assembly = Assembly.Load(AssemblyPath);
return assembly.CreateInstance(className);
}
//返回接口
public static ITestDAL CreateTestDAL()
{
string fullClassName = NameSpase + ".TestDAL";
return CreateInstance(fullClassName) as TestDAL;
}
}
c#通过反射的形式创建类的实例
最新推荐文章于 2024-05-16 16:10:41 发布