我使用工厂模式创建了若干方法例如public ClassFactory
{
public ReturnClass Create(ClassA a) {....}
public ReturnClass Create(ClassB b) {....}
}我只有在运行时才能得到ClassA或者是ClassB的类名的字符串形式,现在我有如下代码ClassFactory cf = new ClassFactory();
string paramName = GetParamName(); //paramName 就是“ClassA”或者“ClassB”//.....这段不会写啊
//得到ClassA或ClassB的实例aReturnClass rc = cf.Create(a);
{
public ReturnClass Create(ClassA a) {....}
public ReturnClass Create(ClassB b) {....}
}我只有在运行时才能得到ClassA或者是ClassB的类名的字符串形式,现在我有如下代码ClassFactory cf = new ClassFactory();
string paramName = GetParamName(); //paramName 就是“ClassA”或者“ClassB”//.....这段不会写啊
//得到ClassA或ClassB的实例aReturnClass rc = cf.Create(a);
解决方案 »
- tabcontrol 标签样式
- C#版本camera控制源码
- 得到 多维数组其中一维的长度?
- 高手指点--正则表达式
- 如何在dataset 中将 type 是string 得字符串放到type 是double 的colunm中,或者怎样将有数据的datatable 中type 为double 的colunm转换成string
- 分享变态的方法让 enum 支持中文,超级好用
- Arraylist 如何添加 SQLserver 表中的数据
- 新手问题!关于连接sqlserver的!!!请前辈指教
- datagrid按列赋值
- 分享一个WPF 与MVVM实现的软件需求变更管理系统
- 烦烦烦...动手能力超差
- C#如何调用SAP GUI功能。
Type type = Type.GetType(className);
result = Activator.CreateInstance(type);
/// <summary>
/// This class is implemented following the Abstract Factory pattern to create the BLL implementation
/// specified from the configuration file
/// </summary>
public sealed class DataAccess
{ // Look up the BLL implementation we should be using
private static readonly string path = "*****.BLL";
private static readonly Assembly bllAssembly = null; static DataAccess()
{
bllAssembly = Assembly.Load(path);
} private DataAccess() { } /// <summary>
/// 创建业务逻辑对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T GetBll<T>()
{
Type type = typeof(T);
return (T)bllAssembly.CreateInstance(type.Namespace.Replace("IBLL", "BLL") + "." + type.Name.Substring(1));
}
}